How to let users run code on a website, for learning? Like educative?
Consider a site that teaches programming, say GoLang or Java. How to let users change the sample code and run it, like educative.io does? Do they have some kind of sandbox environment that runs in the background?
Yes, there no magic. The code is compiled and run on a server. So the flow is HTML with a textarea, the text from that gets sent via HTTP POST to the server, the server then "shells out" and lets the os run `go build` or `javac` and captures stdout and stderr. It runs the compiled program, also capturing stdout and stderr and returns all that text to the user. It can do this as a result of the original HTTP POST or you could have a like a websocket open and the results come back via that.
Yes, it should set up a sandboxed environment, ideally a VM or a "system container" to avoid compiled program to break out and mess up the main system.
I remember playing with such systems for any of those international programming contests and their local brethren (they could compile a program and compare output for a number of test cases).