sandkiln
Client SDK for sandkiln — a compute primitive for safely running untrusted or AI-generated code in hardware-isolated Firecracker microVMs. Each sandbox is a real microVM: its own kernel, its own filesystem, its own network.
This package is the client. It talks to a sandkilnd daemon over HTTP —
you need one running somewhere reachable (see the main repo for how to
run one; there is no hosted service). Zero runtime dependencies —
urllib/asyncio from the standard library is all it needs.
Every class below also ships as an asyncio-native mirror —
AsyncSandbox, AsyncDrive, AsyncImage, AsyncPool — with identical
method names and arguments, just async def and awaited. They're
deliberately separate classes rather than sync+async methods on one
class, since a sync call in an async context blocks the event loop
silently rather than raising a clear error.
Install
pip install sandkiln
Usage
from sandkiln import Sandbox
sandbox = Sandbox.create(tags={"env": "ci"})
result = sandbox.run_command("python3", ["analyze.py"])
print(result.stdout, result.exit_code)
sandbox.write_file("/tmp/config.json", '{"ok": true}')
data = sandbox.read_file("/tmp/config.json")
running = Sandbox.list(tags={"env": "ci"})
sandbox.stop()
Configuration
- Daemon URL: pass
base_urltoSandbox.create()/Sandbox.list(), or setSANDKILN_DAEMON_URL. Defaults tohttp://127.0.0.1:7777. - Auth: pass
auth_token, or setSANDKILN_AUTH_TOKEN, if the daemon hasSANDKILN_AUTH_TOKENset. Omit entirely for an unauthenticated local daemon.
API
Sandbox.create(name=None, tags=None, base_url=None, auth_token=None, vcpu_count=None, mem_size_mib=None, image_id=None, drives=None)— boots a sandbox.nameis a caller-given identity, unique among live sandboxes and held snapshots (409 if already taken) — seeby_name/get_or_createbelow to find it again later.vcpu_count/mem_size_miboverride the daemon's configured defaults for this one sandbox, subject to the daemon's configured ceiling.image_idboots from a registered image (seeImage.registerbelow) instead of the daemon's configured default rootfs.drivesis a list ofDriveAttachmentto attach existing persistent drives (seeDrivebelow). (A few more keyword arguments exist for rate limiting, per-sandbox environment variables, and egress policy — see the full reference in the main repo's docs for all of them.)Sandbox.attach(id, base_url=None, auth_token=None)— wraps an existing sandbox id without a network round-trip.Sandbox.by_name(name, base_url=None, auth_token=None)— resolves a name to a live sandbox and returns a handle to it. RaisesSandkilnApiError(409) if the name currently belongs to a stopped (snapshotted) sandbox instead — useget_or_createif you want that resumed automatically.Sandbox.get_or_create(name, tags=None, base_url=None, auth_token=None, vcpu_count=None, mem_size_mib=None)— resolvesnameto a sandbox in one race-safe call: a live sandbox with this name is returned as-is, a stopped one is resumed, otherwise a fresh one is created and given this name. Returns(sandbox, created).Sandbox.list(tags=None, base_url=None, auth_token=None)— lists sandboxes;tagsfilters by exact match on every given key.sandbox.run_command(command, args=None)— returns anExecResult(stdout,stderr,exit_code).sandbox.read_file(path)— returns file contents asbytes.sandbox.write_file(path, content)—contentisstrorbytes.sandbox.chmod(path, mode),sandbox.chown(path, uid, gid),sandbox.mkdir(path, parents=False),sandbox.rename(from_path, to_path),sandbox.copy(from_path, to_path),sandbox.symlink(target, link_path),sandbox.readlink(path),sandbox.truncate(path, size),sandbox.list_dir(path)(returnslist[DirEntry]with realis_dir/is_symlink/size/mode/mtimemetadata) — the full filesystem operation set.sandbox.preview_url(port, path="/")— the URL a browser can open directly to reach a server listening onportinside this sandbox, proxied through the daemon.sandbox.tunnel(guest_port, local_port, local_host="127.0.0.1")— the reverse ofpreview_url: exposes a service running on this machine to code inside the sandbox. Returns aTunnelHandlewith.tunnel_id/.close(). The tunnel,pty()andattach_logs()share one RFC 6455 WebSocket client hand-rolled on the standard library (there is none to import), so the package still has no dependencies.sandbox.pty(cols=80, rows=24)— a live interactive shell. Returns aPtySession:send(data)is stdin,recv(timeout=None)returns the next chunk of output asbytes(Noneonce the shell ended), and it iterates and works as a context manager. Terminal size applies once at open; there is no live resize.sandbox.exec_stream(command, args=None, env=None)— starts a command detached and returns a session id at once;sandbox.attach_logs(session_id)returns aLogStreamthat replays the captured output then live-tails it (exit_codeis set from the daemon's final notice,read_all()returns aLogOutput);sandbox.list_exec_streams()lists sessions asExecStreamSession.sandbox.upload_dir(local_dir, remote_dir, exclude=None, concurrency=8)/sandbox.download_dir(remote_dir, local_dir, ...)— copy a directory tree with modes and symlinks; return aTransferResult.download_dirtreats the guest as untrusted (unsafe names raiseValueError, symlinks that would leavelocal_dirare skipped and listed).AsyncSandboxhas all of these as awaitables (AsyncPtySession,AsyncLogStream).sandbox.mount(bucket, endpoint, access_key, secret_key, mount_path, read_only=False)— mounts an S3-compatible bucket into the sandbox viarclone mount; ordinaryread_file()/write_file()calls againstmount_paththen read/write through to the bucket. Needs the optional FUSE-capable rootfs setup described inSELF_HOSTING.md.sandbox.list_mounts()— lists every remote-storage mount currently active in the sandbox.sandbox.unmount(mount_id)— tears down one mount.sandbox.stop(keep=None)— stops the sandbox. By default (keepomitted orTrue) this preserves its state as a resumable snapshot, same assnapshot(), and returns aStopResult(kept, snapshot_id). Passkeep=Falsefor the old "just destroy it" behavior — no snapshot, nothing left to resume.sandbox.snapshot()— saves the sandbox's full state to disk and stops it; returns a snapshot id. The daemon can also do this on its own, for an idle sandbox, if the operator hasSANDKILN_AUTO_SUSPEND_TIMEOUT_SECSconfigured — seeSandbox.list_snapshotsbelow for how to notice it and find the resulting snapshot.Sandbox.resume(snapshot_id, base_url=None, auth_token=None)— boots a new sandbox from a snapshot, consuming it (the snapshot is gone afterward).Sandbox.fork(snapshot_id, base_url=None, auth_token=None)— boots a new sandbox from a snapshot without consuming it, so it can be forked or resumed again later. Only one live fork of a given snapshot may run at a time — a second concurrentfork()raisesSandkilnApiErrorwith status 409 until the first is stopped; seedocs/design-notes/snapshots.mdfor why.Sandbox.list_snapshots(source_sandbox_id=None, base_url=None, auth_token=None)— lists snapshots.source_sandbox_idnarrows this to the (at most one) snapshot taken from that original sandbox id — the way to find out whether a sandbox id that dropped out ofSandbox.list()turned into a snapshot (via a manualsnapshot()or the daemon's auto-suspend) and what its new id is.Image.register(id, path, base_url=None, auth_token=None)— registers an already-built ext4 rootfs file atpathon the daemon's own host filesystem underid, forSandbox.create(image_id=...)to boot from. Not a file upload — the daemon can't verify the guest agent is baked in without root access to loop-mount it (ImageInfo.guest_agent_verifiedis alwaysFalse); runscripts/preflight-check.sh --root-checks --rootfs-image <path>out of band first.Image.list(base_url=None, auth_token=None)/Image.delete(id, base_url=None, auth_token=None)— list registered images, or delete one (refused with 409 while any live sandbox, in-flight boot, or held snapshot still references it).Drive.create(size_mib, base_url=None, auth_token=None)— creates a new empty persistent drive, returns its id.Drive.list(base_url=None, auth_token=None)— lists drives, including every current holder and whether each is read-only.Drive.delete(id, base_url=None, auth_token=None)— permanently removes a drive and its backing file (refused with 409 while anything references it). Attach one viaSandbox.create(drives=[DriveAttachment(id=..., read_only=False)])— a drive attached read-only may be shared by many sandboxes at once, read-write needs exclusive access.Pool.create(id, image_id=None, vcpu_count=None, mem_size_mib=None, warm_count=0, max_count=None, base_url=None, auth_token=None)— configures a pre-warmed pool under a caller-givenid(409 if already taken).warm_countis how many resumable snapshots to keep ready;max_countcaps total live instances of this pool's profile (omitted means unbounded) — a create at the ceiling with nothing warm queues for up to 30s instead of exceeding it or rejecting outright.Pool.list(base_url=None, auth_token=None)— lists configured pools, includingwarm_ready(how many are actually ready right now).Pool.delete(id, base_url=None, auth_token=None)— removes a pool's configuration and destroys whatever it currently has warm. There's noPool.claim()— claiming is entirely transparent: a plainSandbox.create()matching a configured pool's image/resources resumes a warm instance instead of cold-booting.
This mirrors the JS/TS SDK
closely — same daemon, same operations, Python-idiomatic naming
(run_command not runCommand, snake_case fields).
Status
Published, and level with the JS/TS SDK:
the same operations, including pty(), streamed background exec and
directory transfer. The two clients' shared gaps are the daemon features
no client wraps yet (snapshot lineage filtering and time-travel restore).
See the
roadmap
for what's next.
License
MIT
Metadata
Release files for sandkiln 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 |
|---|---|---|---|---|
| sandkiln-0.6.0.tar.gz | 53.3 kB | With provenance | Details for sandkiln-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sandkiln-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for sandkiln-0.6.0-py3-none-any.whl |
Total release size: 105.3 kB
Release files / sandkiln-0.6.0.tar.gz
| Download URL | sandkiln-0.6.0.tar.gz |
|---|---|
| Size | 53.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa26a301a80c27f7ead4c802a76079332cf7ea4d5521390fcc77fb4f7bcebcf0
|
|
BLAKE2b-256 checksum How to use checksums |
ccd4aa280b5907207510a0d6efa8fe7d1b4a9d997b62ed3dd2e7f11d248ae213
|
| 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 24, 2026.
Transparency logRelease files / sandkiln-0.6.0-py3-none-any.whl
| Download URL | sandkiln-0.6.0-py3-none-any.whl |
|---|---|
| Size | 51.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
148d7d52f9080c882c9e33d0e875939e3bebdeb969327c7d3dc9c40e21985865
|
|
BLAKE2b-256 checksum How to use checksums |
129c3a1dde6910b3503227ff33ff46f2dca754ae3678dc328426bc217f6b8e13
|
| 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 24, 2026.
Transparency logSecurity for sandkiln 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
Both files in this release have been uploaded with provenance metadata.
Attestation for sandkiln-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 24, 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.