import json
user_code = """
import json
my_data= {"a":[1,2,3]}
print json.dumps(my_data)
"""
with open(USER_CODE_FILE, 'wb') as f:
    f.write(user_code)
user_result_str = subprocess.check_output([PYTHON_PATH, USER_CODE_FILE])
user_result = json.loads(user_result_str)
print(user_result)
Is it possible to restrict access to globals for a block of code in python?