Escaping a Python sandbox (NdH 2013 quals writeup)
blog.delroth.net
blog.delroth.net
Restricted Python will recompile your code from something like "x.y(42)" into your_getattr(x, "y")(42). It will disallow access of any names starting with _, a number of other unsafe constructs etc.
So you can set up your sandbox as restricted as you want. For example the objects I expose have each an ACL so I can give users access to some system object's specific properties while disallowing modifications of them.
> You can get the code object of a function using myfunc.func_code. This is forbidden in the restricted mode of the Python interpreter, so we can’t see the code of the auth function.