Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As pointed out in another subthread, Python code is practically impossible to sandbox. Most competition isolate player code by running it in a separate process which has the additional benefit of easily allowing different implementation languages.

Making sure the process doesn't use your network to spread malware is not 100% trivial but still easier than sandboxing Python code within Python.

Good luck with your project!



Seccomp might be a possibility here, but will require one process per live robot (and Linux). With seccomp your process can do nothing but read/write from its file descriptors (so you have to make sure they are safe) but can do nothing more (thus you cannot import modules). So you can exchange messages via file descriptors and otherwise use any Python (or even any other language at all features). Here's one recent article about it: http://pythonsweetness.tumblr.com/post/65442885019/secure-lo...

RestrictedPython, used in zope, is nice too. However it cuts you out of many Python features that it cannot statically validate.


Seattle[1] includes an attempt to sandbox Python. No idea if it's 100% covered, but they try.

[1]: https://seattle.poly.edu/wiki


Another option might be running PyPy within your CPython only for the user scripting parts and switching everything off you don't want.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: