I\'m currently working on an online C/C++/assembly compiler, and I stumbled upon a nice piece of software called libsandbox. This enables me to run the online written code, comp
The sandbox is for linux only. You must actually create the sandbox first by using the library functions and then tell the sandbox to run your program.
This python sample shows how to do it from python. The line "#targeted program" shows you where you will specify the name of your actual application.
def main(args):
# sandbox configuration
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
'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
msb = MiniSandbox(**cookbook)
msb.run()
# verbose statistics
sys.stderr.write("result: %(result)s\ncpu: %(cpu)dms\nmem: %(mem)dkB\n" % \
msb.probe())
return os.EX_OK
I would recommend going to the libsandbox download page and getting the full sample2.py file there and then just running the sandbox using the python script. This will be easier than making a C++ or C program to do it for you.
So...
Make your C or C++ program. DO NOT LINK IT TO LIBSANDBOX.
Make sure you have python installed.
Run the sample python script from the libsandbox page.
The python script will load the libsandbox for you. Then it will run the program you have built inside the sandbox.
Simple.