title: how to prevent access builtins from exec, eval through function call
body: <p>i have following code</p>
  
  <pre><code>a = 100
  
  def foo(x):
      print "x is {}, a is {}".format(x,a)
      print "locals:" + '*' * 10
      print locals()
      print "globals:" + '*' * 10
      print globals()
      print abs(1)
  
  def main():
  
      source = 'foo(x)'
      l = {'foo':foo, 'x':1}
      exec(source,{'__builtins__': None}, l)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>when a i run this , i still get result as below, but i am expecting that in function <em>foo</em> , i can't access globals, locals, or abs like these builtin functions, any one can help explain this , thanks.</p>
  
  <pre><code>x is 1, a is 100
  locals:**********
  {'x': 1}
  globals:**********
  {'a': 100, 'main': &lt;function main at 0x7f68c1d37c80&gt;, '__builtins__': &lt;module '__builtin__' (built-in)&gt;, '__file__': 'play/eval_test.py', '__package__': None, '__name__': '__main__', 'foo': &lt;function foo at 0x7f68c1d37c08&gt;, '__doc__': None}
  1
  </code></pre>