How to detect and prevent attacks cause by allowing users to run C++ code in a webpage

  c++, html, php, server, web

I want to learn how to create a webpage that can allow users to run C++ or python code online (ex: I was able to do this using g++. In many StackOverflow articles, I have seen others say that we should not allow users to run code in your server, since this is a big security risk. But doesn’t say what are those attacks or how to prevent them. Can you please give us few example codes showing how can they attack? That way I can try to find a way to minimize these attacks. If you know of any mitigation methods, please let me know. Any help would be greatly appreciated.

Source: Windows Questions C++