예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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)