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.
Metadata
Release files for simple-cp-sandbox 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simple_cp_sandbox-0.1.0.tar.gz | 13.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_cp_sandbox-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.2 kB
Release files / simple_cp_sandbox-0.1.0.tar.gz
| Download URL | simple_cp_sandbox-0.1.0.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
860223bc66c451841fa320fba739a6ec030bcb7314063e27cf2410336d958fe4
|
|
BLAKE2b-256 checksum How to use checksums |
44229677e647a798e9bf81f6bf613348a1a9e3b8cb46f1c91342260b3c415db1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.15 Windows/10
|
Release files / simple_cp_sandbox-0.1.0-py3-none-any.whl
| Download URL | simple_cp_sandbox-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6d521a31c3148c407c7896876b5c1b583a7d0c2d0fd8188ea19c388be4ec37b
|
|
BLAKE2b-256 checksum How to use checksums |
f376adec2cc6909e81ee22a8f73d232795d4d7a6c38cce8caaa6f6ffae270d8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.15 Windows/10
|