It could very well be that your computer is overheating. When the computer reaches a certain temperature it can either sound an alarm, or just shutoff, to prevent further damage to the CPU.
When it shuts down, turn it back on and check the temperature.
Enter the BIOS, and determine what the shutoff temp is set at. And you can raise it alittle if it is too low.
The next thing is to remove the case and see if all the fans are working. If they are not, replace them.
Also. if the fans do work, they may not be blowing enough air, you might have to add additional fans or replace the fans with higher performance fans.
Make sure the fan on the power supply case is operating.
If you are overclocking your CPU, STOP.
What CPU do you have? how many fans are in your case?
I currently have 7 fans in my box.
How many Hard drives do you have in the box? Maybe consider adding a harddrive cooler.
What is the amount of watts the power supply case is. If it is too low. it will be working harder, therefore generating more heat. Use a 300Watt PS at minimum on a Gigahertz machine, If you have many peripherals in the box, you might want to consider adding a newer PS, such as a 400 to 500Watt.
If the machine is packed with dust, clean it out as best you can.