Safe execution is hard. This might provide a reasonable solution: https://github.com/edx/codejail