Unexpected shutdowns can have a variety of causes. You say that you have checked for viruses, have you also checked for Malware and Spyware? If not download the free version of Malwarebytes. Assuming that the machine is clean and dust free so that overheating is ruled out then memory is the most common culprit Click Here for how to run a memory test. If that is clear then the next most likely cause is the power supply and there is no easy test for that other than substitution with a known good unit.
Samsung Galaxy S8 review