Commit 543de052 by Ned Batchelder

Hint functions are now run in the sandbox.

parent a5d91834
"""Safe execution of untrusted Python code.""" """Safe execution of untrusted Python code."""
import json import json
import logging
import os.path import os.path
import shutil import shutil
import sys import sys
...@@ -9,6 +10,8 @@ import textwrap ...@@ -9,6 +10,8 @@ import textwrap
from codejail import jailpy from codejail import jailpy
from codejail.util import temp_directory, change_directory from codejail.util import temp_directory, change_directory
log = logging.getLogger(__name__)
def safe_exec(code, globals_dict, files=None, python_path=None): def safe_exec(code, globals_dict, files=None, python_path=None):
"""Execute code as "exec" does, but safely. """Execute code as "exec" does, but safely.
...@@ -78,10 +81,9 @@ def safe_exec(code, globals_dict, files=None, python_path=None): ...@@ -78,10 +81,9 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
# Turn this on to see what's being executed. # Turn this on to see what's being executed.
if 0: if 0:
print "--{:-<40}".format(" jailed ") log.debug("Jailed code: %s", jailed_code)
print jailed_code log.debug("Exec: %s", code)
print "--{:-<40}".format(" exec ") log.debug("Stdin: %s", stdin)
print code
res = jailpy.jailpy(jailed_code, stdin=stdin, files=files) res = jailpy.jailpy(jailed_code, stdin=stdin, files=files)
if res.status != 0: 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