def get_sandbox(): sandbox_config = pysandbox.SandboxConfig() sandbox_config.enable("stdout") sandbox_config.enable("time") sandbox_config.enable("math") sandbox_config.enable("exit") sandbox_config.enable("stderr") sandbox_config.timeout = None sandbox = pysandbox.Sandbox(sandbox_config) return sandbox
def createSandboxConfig(): cfg = S.SandboxConfig( 'stdout', 'stderr', 'regex', 'unicodedata', # flow wants u'\{ATOM SYMBOL}' :-) 'future', 'code', 'time', 'datetime', 'math', 'itertools', 'random', 'encodings', ) cfg.allowModule('sys', 'version', 'hexversion', 'version_info') return cfg
def createSandboxConfig(): cfg = S.SandboxConfig( 'stdout', 'stderr', 'regex', 'unicodedata', # flow wants u'\{ATOM SYMBOL}' :-) 'future', #'code', 'time', 'datetime', 'math', 'itertools', 'random', 'encodings', ) cfg.max_memory = EVAL_MAXMEMORYBYTES cfg.timeout = EVAL_MAXTIMESECONDS cfg.allowModule('sys', 'version', 'hexversion', 'version_info') return cfg
import sys import sandbox from StringIO import StringIO o = '' buf = StringIO() cookbook = { 'stdin': sys.stdin, # input to targeted program 'stderr': sys.stderr, # error from targeted program 'quota': dict( wallclock=30000, # 30 sec cpu=2000, # 2 sec memory=8388608, # 8 MB disk=1048576) } # 1 MB if __name__ == '__main__': user_code = sys.argv[1] box = sandbox.Sandbox(sandbox.SandboxConfig('stdout')) box.execute(user_code)