Running libsandbox

前端 未结 3 1438
梦如初夏
梦如初夏 2021-01-22 12:40

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

3条回答
  •  温柔的废话
    2021-01-22 13:18

    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...

    1. Make your C or C++ program. DO NOT LINK IT TO LIBSANDBOX.

    2. Make sure you have python installed.

    3. Run the sample python script from the libsandbox page.

    4. The python script will load the libsandbox for you. Then it will run the program you have built inside the sandbox.

    Simple.

提交回复
热议问题