For a software solution, you could try reinstalling your operating system, be that Window, OS X or Linux. Also you can open up your task manager (ctrl+alt+del or right click on your start bar and select "Task Manager"), and see if there are any processes that are taking up a lot of memory or processing power.
If none of those fixes it, it may either be a hardware issue or a cooling issue.
If your computer is in a confined space and doesn't have much room to breathe, I suggest moving it to a more open location to try and help ventilate it more. Sometimes, if a computer overheats, it will shutdown automatically to prevent any physical damage to the system.
Your computer may not have enough power to run everything in the system, and so it will shutoff due to the lack of power (kind of like a rolling blackout in a power grid).
If it's none of these, then I would bring it in to a service place to have it looked at.