Google Caja allows you to safely embed Javascript specified by the user on your site, but I think that it can be aimed at running the code on the browser user, and not on your server. I did not use it myself.
I donβt know if there are ready-made solutions for other languages, but I think that the user solution will require recompilation of the interpreter after removing all the API libraries that will allow the user to write to disk, open network connections, fork processes / threads, as well as perform any other operations with dangerous or negative calls. White βsafeβ libraries are the only approach that could work for this.
It would be safer if you had separate virtual servers for individual users.
Leons source share