Anurag Uniyal
Anurag Uniyal

Reputation: 88837

What is python's 'restricted execution mode'?

When __builtins__ is set and I try to access function globals, I get this error

>>> def f(): pass
... 
>>> f.func_globals
{'f': <function f at 0x00B83270>, '__builtins__': <module '__builtin__' (built-in)>}
>>> __builtins__ = {}
>>> f.func_globals
Traceback (most recent call last):
  File "<string>", line 1, in <string>
RuntimeError: restricted attribute
>>> 

Why is that, where I can read more about it? Can I use it to safeguard expression evaluation?

See Question: How safe is expression evaluation using eval?

Upvotes: 1

Views: 2274

Answers (1)

Alex Martelli
Alex Martelli

Reputation: 882211

Alas, a long-obsolete concept, see the docs -- the original idea was to provide a safe / sandboxed mode, but it just didn't pan out and was abandoned and deprecated since 2.3.

Upvotes: 3

Related Questions