I'm trying to set up a Python sandbox and want to forbid access to standard and file I/O. I am running the sandbox inside of a running Python server.
I've already looked at modules like RestrictedPython
and PyPy
; however, I want to be able to compile the sandbox code inside of my running Python server, not through an external process.
Are there any alternative ways to prevent access to commands like print
, raw_input
, or open
? Could the aforementioned modules be used in a way where sandbox code is compiled in a running Python program?
At worst, how would you prevent access to raw_input
?
EDIT: According to this tutorial on safely evaluating Python code, would it be possible to pass in a manipulated builtins module?
)". The issue of imposing memory limits is being addressed here: http://stackoverflow.com/questions/10269974/python-setting-memory-limit-for-a-particular-function-call