Earlier quoted context omitted.
As long as you read the files before you execute them. Otherwise some bad actor could write a virus / local exploit into their submission which will execute when you compile and run the file.
I never execute them. I just grade them by reading the code. Running them takes FAR longer than reading.
How do you know they compile?
How do you know they work?
How do you know they handle all the edge cases you can throw at them.
If you have a 100% accurate parser and compiler in your head, I am impressed.
Our teachers (and this was 15 years ago) had test-runners which would compile and run our programs to make sure they met the requirements of the homework THEN they looked at the code and marked it for style etc.
Sometimes they provided these test runners to us so we could check them ourselves, sometimes they didn't (this was, naturally, harder).