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, compile it and intercept system calls if they're made.
First of all, I'm kind of new in the Linux environment. I've download the tar.gz, unpacked it, configured it and make install it. This ran without any errors, but now I'm having a hard time running it. How am I supposed to run a C/C++ program in this sandbox? Do I have to feed it the .c/.cpp file? The executable after compiling?
It may be a very stupid question. I've searched on internet on how to do it, and read the readme file included but they didn't gave me a clue.
Thanks in advance!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With