Hello Ssmdmdm,
When the computer restarts, are you getting the message "Your computer was restarted because of a problem"? If so, you'll want to use these steps: If your Mac restarted because of a problem
If the computer is just restarting without any error messages, then you'll want to go through general troubleshooting to try and isolate the cause.
If you have any external devices connected to the computer (external hard drives, USB hubs, printers, etc.) disconnect them and see if the unexpected restart continues.
Start the computer in safe mode to see if the issue occurs in that mode. If it does not restart while in safe mode, then that indicates the issue is coming from some software you have installed on the computer. If you noticed the issue started after you installed something on the computer, try removing it to see if that resolves the issue.
Start up your Mac in safe mode
Test another user account on the computer. This will help to isolate if the issue is tied to something in your main user account or if it's a system wide issue. You can use these steps to add another user account to the computer: Add a user or group on Mac Once you create another user account, switch over to it then test out the computer and see if the unexpected restart still occurs.
Cheers!