Zerobox Python SDK
Python SDK for zerobox. Sandbox any command with file, network, and credential controls.
pip install zerobox
Installing the wheel drops the zerobox CLI into your environment's bin/ and exposes a Python SDK.
For CLI usage, secrets concepts, the full flag reference, performance numbers, and platform support see the main README.
Quick start
from zerobox import Sandbox
sandbox = Sandbox.create({"allow_write": ["/tmp"]})
print(sandbox.sh("echo hello").text())
Commands
Three ways to run a command. Each returns a ShellCommand you terminate with .text(), .json(), or .output().
Shell
name = "world"
sandbox.sh(f"echo hello {name}").text()
Inline Python
data = sandbox.py("import json; print(json.dumps({'sum': 1 + 2}))").json()
Explicit command + args
sandbox.exec("python3", ["-c", "print('hi')"]).text()
Results
| Method | On success | On non-zero exit |
|---|---|---|
.text() |
Returns stdout as a string | Raises SandboxCommandError |
.json() |
Parses stdout as JSON | Raises SandboxCommandError |
.output() |
Returns CommandOutput(code, stdout, stderr) |
Returns the same shape, never raises |
data = sandbox.sh("cat data.json").json()
result = sandbox.sh("exit 42").output()
# CommandOutput(code=42, stdout='', stderr='')
Async API
Use AsyncSandbox in async applications so waiting for the sandboxed subprocess
does not block the event loop. The command shape is the same as Sandbox, but
creation and terminators are awaited.
from zerobox import AsyncSandbox
sandbox = await AsyncSandbox.create({"allow_write": ["/tmp"]})
text = await sandbox.sh("echo hello").text()
data = await sandbox.sh("printf '{\"ok\": true}'").json()
result = await sandbox.exec("python3", ["-c", "print('hi')"]).output()
Async commands accept the same timeout option:
import subprocess
try:
await sandbox.sh("sleep 60").text(timeout=1.0)
except subprocess.TimeoutExpired:
print("cancelled")
Error handling
Non-zero exit raises SandboxCommandError:
from zerobox import Sandbox, SandboxCommandError
sandbox = Sandbox.create()
try:
sandbox.sh("exit 1").text()
except SandboxCommandError as e:
print(e.code, e.stderr)
Secrets
Pass API keys that the sandboxed process never sees. The proxy substitutes the real value only for approved hosts.
import os
from zerobox import Sandbox
sandbox = Sandbox.create({
"secrets": {
"OPENAI_API_KEY": {
"value": os.environ["OPENAI_API_KEY"],
"hosts": ["api.openai.com"],
},
"GITHUB_TOKEN": {
"value": os.environ["GITHUB_TOKEN"],
"hosts": ["api.github.com"],
},
},
})
sandbox.sh('curl -H "Authorization: Bearer $OPENAI_API_KEY" https://api.openai.com/v1/models').text()
See the main README for how placeholder substitution works.
Snapshots
Record filesystem changes and roll them back automatically:
sandbox = Sandbox.create({
"allow_write": ["."],
"restore": True,
})
sandbox.sh("npm install").text()
Record without rolling back:
sandbox = Sandbox.create({
"allow_write": ["."],
"snapshot": True,
"snapshot_exclude": ["node_modules"],
})
sandbox.sh("npm install").text()
Cancellation
Pass a timeout (seconds) to any terminator:
import subprocess
try:
sandbox.sh("sleep 60").text(timeout=1.0)
except subprocess.TimeoutExpired:
print("cancelled")
Environment variables
sandbox = Sandbox.create({
"env": {"NODE_ENV": "production"},
"allow_env": ["PATH", "HOME"],
"deny_env": ["AWS_SECRET_ACCESS_KEY"],
})
See the main README for what's inherited by default and the CLI equivalents.
Options
Sandbox.create(options) accepts a SandboxOptions dataclass or a plain dict. All fields are optional.
| Field | Type | Description |
|---|---|---|
profile |
str | list[str] |
Named profile(s). A list merges left-to-right. Default "workspace". |
allow_read / deny_read |
list[str] |
Readable / blocked paths. |
allow_write / deny_write |
list[str] |
Writable / blocked paths. |
allow_net |
bool | list[str] |
True allows all. A list restricts to those domains. |
deny_net |
list[str] |
Blocked domains. |
allow_all |
bool |
Full filesystem + network access. |
no_sandbox |
bool |
Disable the sandbox entirely. |
strict_sandbox |
bool |
Fail instead of falling back to weaker isolation. |
cwd |
str |
Working directory. |
env |
dict[str, str] |
Explicit env vars. |
allow_env |
bool | list[str] |
Inherit parent env vars. |
deny_env |
list[str] |
Blocked env vars. |
snapshot |
bool |
Record filesystem changes. |
restore |
bool |
Record and roll back after exit. Implies snapshot. |
snapshot_paths / snapshot_exclude |
list[str] |
Tracked paths / excluded patterns. |
secrets |
dict[str, SecretConfig] |
Secrets with per-host scopes. |
debug |
bool |
Print sandbox config to stderr. |
Unknown dict keys (e.g. accidental allowWrite instead of allow_write) raise TypeError at construction time.
Caveats
Sandbox.py(code) runs whichever python3 is on PATH inside the sandbox. If your active interpreter lives outside the sandbox's readable roots (for example uv-managed Pythons under ~/.local/share/uv/), fall back to:
import sys
sandbox = Sandbox.create({"allow_read": [sys.prefix]})
sandbox.exec(sys.executable, ["-c", "print('hi')"]).text()
Other SDKs
- TypeScript SDK (npm:
zerobox) - Rust SDK (crates.io:
zerobox)
License
Apache-2.0
Metadata
Release files for zerobox 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| zerobox-0.3.3.tar.gz | 15.0 kB | With provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| zerobox-0.3.3-py3-none-musllinux_1_1_x86_64.whl | Python 3 | none | Linux musl 1.1+ x86-64 | Details |
| zerobox-0.3.3-py3-none-musllinux_1_1_aarch64.whl | Python 3 | none | Linux musl 1.1+ ARM64 | Details |
| zerobox-0.3.3-py3-none-manylinux_2_17_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details |
| zerobox-0.3.3-py3-none-manylinux_2_17_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details |
| zerobox-0.3.3-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
| zerobox-0.3.3-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details |
Total release size: 45.2 MB
Release files / zerobox-0.3.3.tar.gz
| Download URL | zerobox-0.3.3.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb7efb6c48c577619d73f213b67c1b61beb94926474ae8319627a83e7eb9d15b
|
|
BLAKE2b-256 checksum How to use checksums |
096c1c83730fe4db1aeaa4ecdf9de03ab776b0fb62679d7eb975d29504807842
|
| 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 17, 2026.
Transparency logRelease files / zerobox-0.3.3-py3-none-musllinux_1_1_x86_64.whl
| Download URL | zerobox-0.3.3-py3-none-musllinux_1_1_x86_64.whl |
|---|---|
| Size | 8.5 MB |
| Tags | Linux musl 1.1+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
415a8e94c4ef9b06d96869c9d5058b6632f0a970a5f8480cddd1ac17b41954a9
|
|
BLAKE2b-256 checksum How to use checksums |
f42f60585b80ccfe4f983867d35378113ee9ca6a7a9889f92ce492bbd61e1260
|
| 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 17, 2026.
Transparency logRelease files / zerobox-0.3.3-py3-none-musllinux_1_1_aarch64.whl
| Download URL | zerobox-0.3.3-py3-none-musllinux_1_1_aarch64.whl |
|---|---|
| Size | 8.0 MB |
| Tags | Linux musl 1.1+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
69bb74eba97032a8f2fedbec21ed1a6263209889e8826e61944dd28fcb83955a
|
|
BLAKE2b-256 checksum How to use checksums |
bc9debc8674334e3259a756f75a260c89b50b71ee22b745abcdf3457fab4a63c
|
| 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 17, 2026.
Transparency logRelease files / zerobox-0.3.3-py3-none-manylinux_2_17_x86_64.whl
| Download URL | zerobox-0.3.3-py3-none-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 7.1 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
f542c50a71ea53242effb42fad315662d535a058c230b029b1b6125649583ad6
|
|
BLAKE2b-256 checksum How to use checksums |
06ea3ade9fc48f79d18482ec5ae6f043c8da40b4fb78453d114c723cd7b29a1a
|
| 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 17, 2026.
Transparency logRelease files / zerobox-0.3.3-py3-none-manylinux_2_17_aarch64.whl
| Download URL | zerobox-0.3.3-py3-none-manylinux_2_17_aarch64.whl |
|---|---|
| Size | 6.7 MB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
7488f322ac82011bac8f5968e9a5aeb86446eb9c1d52bb807025cc3b7590e9ab
|
|
BLAKE2b-256 checksum How to use checksums |
933cc23d3101a55f09cc2d8dc1e342aae8189650536a7c094dfeeb2a4a2badbb
|
| 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 17, 2026.
Transparency logRelease files / zerobox-0.3.3-py3-none-macosx_11_0_arm64.whl
| Download URL | zerobox-0.3.3-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ab26032423cc01e5cf1074a67f7557c4b86acdb94222f8b36f1c90a677e5709f
|
|
BLAKE2b-256 checksum How to use checksums |
ca6ce44041a4295e895ff424294ac6a61bcc7afdc7ef3f47b8d8f10d475b8e65
|
| 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 17, 2026.
Transparency logRelease files / zerobox-0.3.3-py3-none-macosx_10_12_x86_64.whl
| Download URL | zerobox-0.3.3-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 7.7 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
5d066192b4fc71abfbe574de38548bb7a1d38fe9993dc408832a03b7c6e06ca5
|
|
BLAKE2b-256 checksum How to use checksums |
1f51fe4177db8fc0a41a491dd893dd9793ee9692d5b9f0820686335bba4263b4
|
| 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 17, 2026.
Transparency logSecurity for zerobox 0.3.3
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
All 7 files in this release have been uploaded with provenance metadata.
Attestation for zerobox-0.3.3.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 17, 2026.
Transparency logA 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.