I'm trying to write a simple judge that will compile and execute user submitted c files. I found libsandbox and a question here on stackoverflow.
I have installed the python module and as per the instructions I'm trying to run a hello world program written in C
➜ sandbox git:(V_0_3_x) ✗ ./hello
Hello World%
➜ sandbox git:(V_0_3_x) ✗ python sample2.py hello
result: RF
cpu: 2ms
mem: 288kB
As you can see, when I run the program in the sandbox I don't get any output. It'd be great if someone could tell me how to correctly use it.
The sample code of libsandbox
forbids system calls for file operations, such as open()
, stat()
, close()
. That said, you'll need to either (1) link the hello world program statically to avoid opening files such as shared libraries (i.e. libc.so
), or (2) write a customized sandbox policy that permits relevant system calls. Some examples on customizing sandbox policies can be found at https://github.com/liuyu81/TR-OJA-201209A.
DISCLAIMER: I am the author of libsandbox
.