I want to execute code for an online-judge project.
I couldn't find documentation for the Python wrapper of libsandbox I've found sample2.py and some test cases but without explanations.
What are the defaults when creating a sandbox? Is it secure by default?
I want to execute untrusted code and - Limit CPU - Limit Memory - Limit execution time - Allow read/write access only to a specific folder and limit the size of this folder. - Block network IO. - Block executing other programs.
This code combines two examples I found:
cookbook = {
'args': args[1:], # targeted program
'stdin': sys.stdin, # input to targeted program
'stdout': sys.stdout, # output from targeted program
'stderr': sys.stderr, # error from targeted program
'jail': './foo',
'owner': 'nobody',
'quota': dict(wallclock = 30000,# 30 sec
cpu = 2000, # 2 sec
memory = 8388608, # 8 MB
disk = 1048576)} # 1 MB
# create a sandbox instance and execute till end
s = Sandbox(**cookbook)
s.run()
s.result == S_RESULT_OK
What does disk in quota limit? Does it limit the total bytes the script can write in this run or the size of the folder? What does setting owner to nobody do? Will the code in my example block executing arbitrary code, block network IO and block access to files outside of the jailed folder?
Thanks