Hardened Python sandbox for running untrusted code — subprocess, seccomp, landlock strategies with Z3 formal verification.
Project description
hydra-sandbox
Hardened Python execution sandbox for running untrusted code.
Built for developers building LLM agents, code review bots, and online coding platforms who need to execute user-submitted or model-generated code without risking the host system.
Features
- Multiple isolation strategies — subprocess (cross-platform), seccomp (Linux syscall filtering), landlock (Linux filesystem sandbox)
- Import guard — blocks dangerous stdlib modules (
subprocess,ctypes,socket,multiprocessing, etc.) - Network isolation — monkey-patches
socket.socketto block outbound connections - Resource limits — CPU time, memory, and file descriptor caps (POSIX)
- Secret purging — strips API keys and tokens from the child environment
- AST signature verification — validates function name and parameter lists before execution (zero latency, no LLM cost)
- Z3 formal verification — optional pre/post-condition checking with mathematical proofs
Installation
pip install hydra-sandbox
# With optional dependencies
pip install hydra-sandbox[verify] # Z3 formal verification
pip install hydra-sandbox[seccomp] # Linux seccomp support
pip install hydra-sandbox[landlock] # Linux landlock support
pip install hydra-sandbox[all] # everything
Quick start
from hydra_sandbox import execute_python
# Run untrusted code in an isolated subprocess
result = execute_python(
"print(1 + 1)",
timeout=5,
)
print(result.success) # True
print(result.stdout) # "2"
print(result.exit_code) # 0
Strategy selection
# Auto-detect the strongest available strategy (default)
result = execute_python(code, strategy="auto")
# Explicit strategies
result = execute_python(code, strategy="subprocess") # cross-platform
result = execute_python(code, strategy="seccomp") # Linux only
result = execute_python(code, strategy="seccomp+landlock") # strongest
AST verification
from hydra_sandbox import verify_ast_signature, extract_expected_signature
# Verify a function signature without executing
error = verify_ast_signature(
"def add(x, y): return x + y",
"add",
["x", "y"],
)
print(error) # None — signature is correct
# Extract expected signature from a description
sig = extract_expected_signature(
"Write function 'process(data: bytes, key: str) -> str'"
)
print(sig) # ("process", ["data", "key"])
Z3 formal verification
from z3 import Int
from hydra_sandbox.verify import check_spec, VerificationSpec
x, y = Ints("x y")
spec = VerificationSpec(
precondition=x > 0,
postcondition=x + y > y,
)
result = check_spec(spec)
print(result.valid) # True — mathematically proven
Security
See SECURITY.md for the threat model and supported versions.
The subprocess strategy provides Python-level isolation suitable for
most use cases. For production deployments handling truly untrusted code,
use seccomp+landlock on a Linux host with additional hardening.
Telemetry
hydra-sandbox includes optional, opt-in telemetry. It is disabled by default and sends nothing unless you explicitly enable it.
When enabled, it sends exactly two data points ONCE per process lifetime:
- Package version (
__version__) - Strategy selected (
subprocess,seccomp, etc.)
No user code, no environment variables, no PII, no IP address logging.
export HYDRA_SANDBOX_TELEMETRY=1 # opt in
export HYDRA_SANDBOX_NO_TELEMETRY=1 # explicitly opt out (default)
License
MIT — see LICENSE for details.
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 hydra_sandbox-0.1.0.tar.gz.
File metadata
- Download URL: hydra_sandbox-0.1.0.tar.gz
- Upload date:
- Size: 49.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1d4e8e9493d6a7173fa7ee84e7a87a2dc24820c0a0d303c2687dfbb2b9515ab
|
|
| MD5 |
06fc24d8d6f3cebae7eec4d459fa42d6
|
|
| BLAKE2b-256 |
7d4b0948ac7dc782bf62e2ed1a1811925761f3c728cf48d6a0aaf8bc02761f6d
|
Provenance
The following attestation bundles were made for hydra_sandbox-0.1.0.tar.gz:
Publisher:
publish.yml on akaradje/hydra-sandbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hydra_sandbox-0.1.0.tar.gz -
Subject digest:
d1d4e8e9493d6a7173fa7ee84e7a87a2dc24820c0a0d303c2687dfbb2b9515ab - Sigstore transparency entry: 1503827257
- Sigstore integration time:
-
Permalink:
akaradje/hydra-sandbox@3febf2471efb3f403836a5291c100676995b54ac -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/akaradje
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3febf2471efb3f403836a5291c100676995b54ac -
Trigger Event:
push
-
Statement type:
File details
Details for the file hydra_sandbox-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hydra_sandbox-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e57e2f5f1b55beb2a452c9efc2a49953401d4c45519d7d3b7a71c256b74614c6
|
|
| MD5 |
9416cd65d7d577bb7a54370db433204a
|
|
| BLAKE2b-256 |
70db3a0d99c10083f80a1bf7a578009b29c44d29fcc2efbdb428c555b181810a
|
Provenance
The following attestation bundles were made for hydra_sandbox-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on akaradje/hydra-sandbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hydra_sandbox-0.1.0-py3-none-any.whl -
Subject digest:
e57e2f5f1b55beb2a452c9efc2a49953401d4c45519d7d3b7a71c256b74614c6 - Sigstore transparency entry: 1503827429
- Sigstore integration time:
-
Permalink:
akaradje/hydra-sandbox@3febf2471efb3f403836a5291c100676995b54ac -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/akaradje
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3febf2471efb3f403836a5291c100676995b54ac -
Trigger Event:
push
-
Statement type: