title: Dangerous Python Keywords?
body: <p>I am about to get a bunch of python scripts from an untrusted source.</p>
  
  <p>I'd like to be sure that no part of the code can hurt my system, meaning:</p>
  
  <p><code>(1) the code is not allowed to import ANY MODULE</code></p>
  
  <p><code>(2) the code is not allowed to read or write any data, connect to the network etc</code></p>
  
  <p>(the purpose of each script is to loop through a list, compute some data from input given to it and return the computed value)</p>
  
  <p>before I execute such code, I'd like to have a script 'examine' it and make sure that there's nothing dangerous there that could hurt my system.</p>
  
  <p>I thought of using the following approach: <code>check that the word 'import' is not used (so we are guaranteed that no modules are imported)</code></p>
  
  <p>yet, it would still be possible for the user (if desired) to write code to read/write files etc (say, using <code>open</code>). </p>
  
  <p>Then here comes the question:</p>
  
  <p>(1) where can I get a 'global' list of python methods (like <code>open</code>)? </p>
  
  <p>(2) Is there some code that I could add to each script that is sent to me (at the top) that would make some 'global' methods invalid for that script (for example, any use of the keyword <code>open</code> would lead to an exception)?</p>
  
  <p>I know that there are some solutions of python sandboxing. but please try to answer this question as I feel this is the more relevant approach for my needs.</p>
  
  <p><strong>EDIT:</strong> suppose that I make sure that no <code>import</code> is in the file, and that no possible hurtful methods (such as <code>open</code>, <code>eval</code>, etc) are in it. can I conclude that the file is SAFE? (can you think of any other 'dangerous' ways that built-in methods can be run?)</p>