Commit 543de052 by Ned Batchelder

Hint functions are now run in the sandbox.

parent a5d91834
"""Safe execution of untrusted Python code."""
import json
import logging
import os.path
import shutil
import sys
......@@ -9,6 +10,8 @@ import textwrap
from codejail import jailpy
from codejail.util import temp_directory, change_directory
log = logging.getLogger(__name__)
def safe_exec(code, globals_dict, files=None, python_path=None):
"""Execute code as "exec" does, but safely.
......@@ -78,10 +81,9 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
# Turn this on to see what's being executed.
if 0:
print "--{:-<40}".format(" jailed ")
print jailed_code
print "--{:-<40}".format(" exec ")
print code
log.debug("Jailed code: %s", jailed_code)
log.debug("Exec: %s", code)
log.debug("Stdin: %s", stdin)
res = jailpy.jailpy(jailed_code, stdin=stdin, files=files)
if res.status != 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment