sandstorm — Python SDK
E2B-compatible sandbox API for a Sandstorm master.
The SDK talks to the master over HTTP, so all it needs is the master's address and credentials. It has no dependencies, and nothing else has to be installed on the client machine.
pip install sandstorm-sdk
export SANDSTORM_URL=https://master.example:8080
export SANDSTORM_TOKEN="$(sudo cat /var/lib/sandstorm/pki/api-token)"
export SANDSTORM_CA=ca.pem
A client verifies the name it connects to, and a master's certificate names only
127.0.0.1, localhost and its --bind address. So start this one with
--tls-san master.example.
from sandstorm import Sandbox
with Sandbox("python") as sandbox: # a template on the master
result = sandbox.commands.run("python3 -c 'print(2 + 2)'")
print(result.stdout) # 4
print(result.exit_code) # 0
Or with explicit lifecycle:
sandbox = Sandbox.create("python")
result = sandbox.commands.run("echo hello")
sandbox.kill()
Sandbox returns once a node reports the sandbox running, and removes it if
it never starts. A sandbox that has not started within start_timeout seconds
(default 60) raises RuntimeError, with the node's reason when there is one.
A template whose program fails to load raises after about 15 seconds. A program
that starts and then exits is not caught here: Sandbox returns, and commands
fail while the node restarts it.
Connecting to the master
| Variable | Meaning |
|---|---|
SANDSTORM_URL |
Master base URL. Defaults to https://127.0.0.1:8080, where a master listens unless you bound it elsewhere. |
SANDSTORM_TOKEN |
The master's API token, in pki/api-token under its state directory. |
SANDSTORM_CA |
PEM bundle to verify an https:// master. A master signs its certificate with a CA of its own, so this is usually its pki/ca.pem. |
SANDSTORM_TEMPLATE |
Template for Sandbox() when none is given. |
SANDSTORM_TAG |
Snapshot tag for Sandbox() when no template or tag is given. |
To reach a master in code rather than through the environment, pass a
Controller:
from sandstorm import Controller, Sandbox
master = Controller(base_url="https://master.example:8080", token="...", ca_file="ca.pem")
sandbox = Sandbox("python", controller=master)
Starting from a snapshot
Pass tag to fork from a snapshot instead of starting a template cold:
with Sandbox(tag="checkpoint-1") as sandbox:
print(sandbox.commands.run("ls /work").stdout)
Many sandboxes
Sandbox holds one sandbox. To fork many at once, use Controller and wrap
each child with Sandbox.connect. Each child has its own token, returned only
when it is created:
master = Controller()
children = master.spawn_sandboxes("checkpoint-1", n=5)
sandboxes = [
Sandbox.connect(child["id"], child["token"], controller=master)
for child in children
]
kill and a with block terminate a connected sandbox too.
Controller is also how to branch a running sandbox into a new tag and manage
snapshots.
Running a snippet
eval runs code through the template's eval_argv, python3 -c by default,
and returns what it printed. It is a fresh process each time, and an exception
raises RuntimeError with the snippet's stderr:
with Sandbox("python") as sandbox:
sandbox.eval("print(2 + 2)") # '4\n'
Errors
A call the master refuses raises ControllerError, with the HTTP status in
status and the response in body. For example, a command in a sandbox that
has gone idle is a 409 until it is brought back with POST /v1/sandboxes/:id/touch.
A command that exits non-zero is not an error: read exit_code on the result.
Status
Pre-alpha. Currently supports:
Sandbox(template)/Sandbox(tag=...)/Sandbox.create(...)— create one sandboxSandbox.connect(id, token)— wrap a sandbox that already existssandbox.commands.run(cmd)— run command, get stdout/stderr/exit_codesandbox.eval(code)— run a snippet, get what it printedsandbox.ping()— ask the master about the sandboxsandbox.kill()— terminate
Not yet:
sandbox.files.read/write— filesystem operations- Streaming output
Metadata
Release files for sandstorm-sdk 0.6.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 | Provenance | Actions |
|---|---|---|---|---|
| sandstorm_sdk-0.6.0.tar.gz | 15.1 kB | With provenance | Details for sandstorm_sdk-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sandstorm_sdk-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for sandstorm_sdk-0.6.0-py3-none-any.whl |
Total release size: 26.2 kB
Release files / sandstorm_sdk-0.6.0.tar.gz
| Download URL | sandstorm_sdk-0.6.0.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
970c9b820d307aced202289a125663a2f41913ed746b93d5f70177214717fc72
|
|
BLAKE2b-256 checksum How to use checksums |
0d7061eb183774a0899ec7295c3b999e08f410f41fb6f34fe5a42fa89522842d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 1, 2026.
Transparency logRelease files / sandstorm_sdk-0.6.0-py3-none-any.whl
| Download URL | sandstorm_sdk-0.6.0-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42cc22eb386301282249c5b76a9496872efc3f9ddad567caa903532ee04d8b4a
|
|
BLAKE2b-256 checksum How to use checksums |
f0beced26188c6ecf69f246f7f813d571239e967e568b90c333f1c83325c61ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 1, 2026.
Transparency logSecurity for sandstorm-sdk 0.6.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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for sandstorm_sdk-0.6.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 Nov 1, 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.