First thought is heat. Then failing PSU, failing RAM, failing motherboard, or failing CPU.
I would start by ensuring the interior is clean of heat trapping dust and all fans spin freely. Inspect for any bulging or leaking capacitors. The capacitors are soda can shaped and should be flat on top. If leaking, you will see white to dark brown, dried foam oozing out typically from the tops or bottoms. If bulging, they are under excessive pressure and will likely soon start to leak.
If the interior is already clean, caps look good, your temps are not excessive and fans spin properly, then swap in a known good PSU since everything else depends on good, clean power.
After that, if still shutting down, if your RAM is in two sticks, try just one at time.
You might also look in Event Viewer at the seconds before it shuts down to see if there are any errors logged. But note if the shutdown is too sudden, there may not be any log entries.