Create a gist now

Instantly share code, notes, and snippets.

exec_sandbox.py
import sys
from cStringIO import StringIO
sys.path = [
'/opt/pypy-sandbox',
'/opt/pypy-sandbox/lib_pypy',
'/opt/pypy-sandbox/lib-python/modified-2.5.2',
'/opt/pypy-sandbox/lib-python/2.5.2',
'/opt/pypy-sandbox/lib-python/2.5.2/plat-linux2'
]
from pypy.translator.sandbox import pypy_interact
TIMEOUT = 5
SANDBOX_BIN = 'pypy-sandbox'
def exec_sandbox(code):
sandproc = pypy_interact.PyPySandboxedProc(
SANDBOX_BIN,
['-c', code,'--timeout',str(TIMEOUT)]
)
try:
code_output = StringIO()
sandproc.interact(stdout=code_output, stderr=code_output)
return code_output.getvalue()
except:
sandproc.kill()
finally:
sandproc.kill()
return 'Error, could not evaluate'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment