Skip to main content

hydra-sandbox

PyPI Python License Tests Coverage

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.socket to 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.

Metadata

Release files for hydra-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)

Source distribution for hydra-sandbox 0.1.0
File Size Uploaded Provenance Actions
hydra_sandbox-0.1.0.tar.gz 49.5 kB With provenance Details for hydra_sandbox-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hydra-sandbox 0.1.0
File Interpreter ABI Platform Actions
hydra_sandbox-0.1.0-py3-none-any.whl Python 3 none any Details for hydra_sandbox-0.1.0-py3-none-any.whl

Total release size: 75.5 kB

Release files / hydra_sandbox-0.1.0.tar.gz

Download URL hydra_sandbox-0.1.0.tar.gz
Size 49.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d1d4e8e9493d6a7173fa7ee84e7a87a2dc24820c0a0d303c2687dfbb2b9515ab
BLAKE2b-256 checksum
How to use checksums
7d4b0948ac7dc782bf62e2ed1a1811925761f3c728cf48d6a0aaf8bc02761f6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 11, 2026.

Transparency log

Release files / hydra_sandbox-0.1.0-py3-none-any.whl

Download URL hydra_sandbox-0.1.0-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e57e2f5f1b55beb2a452c9efc2a49953401d4c45519d7d3b7a71c256b74614c6
BLAKE2b-256 checksum
How to use checksums
70db3a0d99c10083f80a1bf7a578009b29c44d29fcc2efbdb428c555b181810a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 11, 2026.

Transparency log

Security for hydra-sandbox 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hydra_sandbox-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page