Sandbox
Create, run, clean up — the basic loop
Sandbox.create(name=None, tags=None, base_url=None, auth_token=None, vcpu_count=None, mem_size_mib=None, image_id=None, rate_limit=None, drives=None)— boots a sandbox.nameis a caller-given identity, unique among live sandboxes and held snapshots (409if already taken) — seeby_name/get_or_createbelow.vcpu_count/mem_size_miboverride the daemon’s configured defaults, subject to its ceiling.image_idboots from a registered image instead of the default rootfs (see Image).rate_limitcaps host I/O via Firecracker’s own token-bucket limiter (unlimited if omitted).drivesis a list ofDriveAttachmentto attach existing persistent drives (see Drive). A call with nodrives/rate_limitmatching a configured pool’s image/resources transparently resumes a warm snapshot instead of cold-booting — see Pool.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.stop(keep=None)— stops the sandbox. Default (keepomitted orTrue) preserves state as a resumable snapshot, returns aStopResult(kept, snapshot_id).keep=Falsefully destroys instead.
Attaching to an id you already have
Sandbox.attach(id, base_url=None, auth_token=None)— wraps an existing sandbox id without a network round-trip.
Named sandboxes — find the same environment again later
Sandbox.by_name(name, base_url=None, auth_token=None)— resolves a name to a live sandbox. RaisesSandkilnApiError(409) if the name currently belongs to a stopped (snapshotted) sandbox instead — useget_or_createfor that.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: live as-is, resumed if stopped, created fresh otherwise. Returns(sandbox, created).
Listing and filtering
Sandbox.list(tags=None, base_url=None, auth_token=None)— lists sandboxes;tagsfilters by exact match on every given key.
Dev-server preview
sandbox.preview_url(port, path="/")— the URL a browser can open to reach a server listening onportinside the sandbox.
Local tunnel
The reverse of preview: expose a service running on this machine to code inside the sandbox. This package’s only WebSocket-based feature — hand-rolled (RFC 6455 handshake and frame masking), since the standard library has no WebSocket client.sandbox.tunnel(guest_port, local_port, local_host="127.0.0.1")— returns aTunnelHandlewith.tunnel_idand.close(). The relay runs on a background thread (AsyncSandbox.tunnel(...)runs it as anasyncio.Taskinstead). See Local tunnel.
Snapshot, resume, fork
sandbox.snapshot()— saves full state to disk and stops; returns a snapshot id.Sandbox.resume(snapshot_id, base_url=None, auth_token=None)— boots from a snapshot, consuming it.Sandbox.fork(snapshot_id, base_url=None, auth_token=None)— boots from a snapshot without consuming it. RaisesSandkilnApiError(409) while an earlier fork is still live.Sandbox.list_snapshots(source_sandbox_id=None, base_url=None, auth_token=None)— lists snapshots.source_sandbox_idnarrows to the one taken from that original sandbox id.
Remote storage mounts
sandbox.mount(bucket, endpoint, access_key, secret_key, mount_path, read_only=False)— mounts an S3-compatible bucket atmount_pathviarclone mount.endpointis the full URL of the S3-compatible service, never defaulted;access_key/secret_keyare written into a0600rclone config file inside the guest, never passed as a command-line argument. Needs the optional FUSE-capable rootfs setup inSELF_HOSTING.md; raisesSandkilnApiErroron a guest-side mount failure. Not carried acrossresume()/fork()— it’s a live guest FUSE process, already captured by Firecracker’s own snapshot.sandbox.list_mounts()— lists every remote-storage mount currently active in this sandbox.sandbox.unmount(mount_id)— tears down one mount. Best-effort on the guest side — a failedumountis a daemon-log warning, not a failed request.