A small fail-closed sandbox runner for competitive-programming style executables.
Project description
simple-cp-sandbox
A small Python package for running an executable in a fail-closed sandbox.
The target profile is useful for competitive-programming style runners:
- the child may read normal files except configured deny-listed directories;
- writes to the filesystem are denied except configured allow-listed directories;
- stdout and stderr are captured;
- network syscalls are denied;
- privilege escalation is blocked with
no_new_privs/seccomp; - the whole child process group can be killed on timeout.
Platform support
| Platform | Status |
|---|---|
| Linux amd64 | Implemented with Landlock, seccomp-BPF, no_new_privs, and a process group. Requires Linux Landlock ABI 3+ so truncation can be blocked. |
Only Linux amd64 is supported.
Documentation
- Implementation principles describes the API flow, Linux backend, Landlock filesystem policy, seccomp syscall policy, timeout handling, and security boundaries.
Install
python -m pip install -e .
Python API
from simple_cp_sandbox import run_executable
result = run_executable("./program", ["arg1", "arg2"], timeout=2.0)
print(result.returncode)
print(result.stdout.decode())
print(result.stderr.decode())
print(result.elapsed)
print(result.timed_out)
For manual lifecycle control:
from simple_cp_sandbox import start_executable
process = start_executable("./program")
result = process.communicate(timeout=2.0)
To deny reads from selected directories and allow writes only inside selected directories:
from simple_cp_sandbox import SandboxConfig, run_executable
config = SandboxConfig(
read_deny_paths=("/home/runner/private",),
write_allow_paths=("/home/runner/workdir",),
)
result = run_executable("./program", config=config)
The paths in read_deny_paths and write_allow_paths must be existing directories.
CLI
simple-cp-sandbox --timeout 2.0 ./program arg1 arg2
You can also run it as a module:
python -m simple_cp_sandbox --timeout 2.0 ./program arg1 arg2
Filesystem policy can be configured from the CLI:
simple-cp-sandbox \
--deny-read /home/runner/private \
--allow-write /home/runner/workdir \
--timeout 2.0 \
./program arg1 arg2
The CLI writes the captured child stdout/stderr back to the runner's stdout/stderr. It exits with 124 on timeout and 125 if the sandbox cannot be created.
Security notes
This package is intentionally conservative:
- Filesystem read/write policy uses Landlock. Read deny paths are excluded from the read rules, and write-like rights are granted only under
write_allow_paths. - seccomp denies networking, namespace creation, mount/module/keyring/BPF/io_uring style syscalls, and filesystem metadata syscalls such as chmod/chown/xattr changes.
- The parent starts the child in a new process group and kills that group with
SIGKILLon timeout or explicitkill(). - Do not run the sandbox parent as root. By default the Linux backend refuses to start when
geteuid() == 0.
This is still a small sandbox runner, not a full VM or container runtime. Use stronger isolation for hostile, high-value, or multi-tenant workloads.
AI implementation notice
This project was implemented entirely by Codex. Users should review the code and understand the risks of AI-generated software, especially for security-sensitive sandboxing code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_cp_sandbox-0.1.0.tar.gz.
File metadata
- Download URL: simple_cp_sandbox-0.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
860223bc66c451841fa320fba739a6ec030bcb7314063e27cf2410336d958fe4
|
|
| MD5 |
bcd4e85fb3ee70f93463a39ee812f2b2
|
|
| BLAKE2b-256 |
44229677e647a798e9bf81f6bf613348a1a9e3b8cb46f1c91342260b3c415db1
|
File details
Details for the file simple_cp_sandbox-0.1.0-py3-none-any.whl.
File metadata
- Download URL: simple_cp_sandbox-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6d521a31c3148c407c7896876b5c1b583a7d0c2d0fd8188ea19c388be4ec37b
|
|
| MD5 |
997006808a14fbcaf2f52eb71f0d7300
|
|
| BLAKE2b-256 |
f376adec2cc6909e81ee22a8f73d232795d4d7a6c38cce8caaa6f6ffae270d8c
|