sandbox0

module
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2026 License: Apache-2.0

README

Sandbox0 logo

Docs Self-hosted License

Sandbox0

Persistent, encrypted sandboxes for long-running AI agents, scheduled by Nomad and isolated by gVisor.

Sandbox0 is an open-source runtime for platforms that need to execute untrusted code without treating every workspace as disposable. A physical runtime allocation is replaceable; the sandbox identity and writable RootFS are durable.

Sandbox0 Cloud uses https://api.sandbox0.ai for sandboxes, templates, credentials, and team-scoped API keys.

Sandbox0 is under active development. Prefer the SDKs and s0 CLI over hardcoded HTTP paths, and check the docs before depending on beta surfaces.

Why Sandbox0

Differentiator What it means
Storage and compute are separated Writable RootFS generations are application-encrypted and stored in S3-compatible object storage. Compute nodes keep disposable caches, not the durable source of truth.
The sandbox lifetime is policy-controlled ttl and hard_ttl default to 0 (disabled). Pause idle compute and later resume the same sandbox identity, or keep it running.
gVisor isolation Stock runsc provides a per-sandbox application-kernel boundary on dedicated Nomad client nodes.
One resource-neutral warm pool Warm Nomad carrier allocations are compatible by immutable runtime properties, not CPU or memory size. Claim-time CPU and memory are leased atomically from node capacity.
Durable environment reuse Snapshot, restore, fork, and template-from-sandbox use immutable block-COW RootFS generations rather than republishing mutable workspace state as an image.

Quickstart

Install the s0 CLI:

curl -fsSL https://raw.githubusercontent.com/sandbox0-ai/s0/main/scripts/install.sh | bash

Windows PowerShell:

irm https://raw.githubusercontent.com/sandbox0-ai/s0/main/scripts/install.ps1 | iex

Sign in and create a team-scoped API key:

s0 auth login

# If no team is selected yet:
# s0 team list
# s0 team create --name my-team --home-region <region-id>
# s0 team use <team-id>

export SANDBOX0_TOKEN="$(s0 apikey create --name sdk-quickstart --role developer --expires-in 30d --raw)"

SDKs default to https://api.sandbox0.ai. Set SANDBOX0_BASE_URL only for a self-hosted or private deployment.

# Python 3.9+
pip install sandbox0

# Node.js 18+
npm install sandbox0

# Go 1.25+
go get github.com/sandbox0-ai/sdk-go

Claim a sandbox, keep state in a REPL context, and run an isolated command:

import os

from sandbox0 import Client
from sandbox0.apispec.models.sandbox_config import SandboxConfig

client = Client(
    token=os.environ["SANDBOX0_TOKEN"],
    base_url=os.environ.get("SANDBOX0_BASE_URL", "https://api.sandbox0.ai"),
)

with client.sandboxes.open(
    "default",
    config=SandboxConfig(ttl=300, hard_ttl=3600),
) as sandbox:
    sandbox.run("python", "x = 41")
    second = sandbox.run("python", "print(x + 1)")
    print(second.output_raw, end="")

    result = sandbox.cmd("/bin/sh -c 'pwd && ls -la'")
    print(result.output_raw, end="")

More examples:

Runtime And Storage Model

flowchart LR
    api["Regional API"] --> manager["manager"]
    manager --> pg[("PostgreSQL")]
    manager --> slot["resource-neutral<br/>Nomad carrier"]
    manager --> ctld["ctld A/B<br/>node runtime"]
    ctld --> lease["dynamic resource lease<br/>cgroup v2"]
    slot --> driver["Sandbox0 task driver"]
    driver --> runsc["stock runsc + procd"]
    runsc <--> ctld
    ctld --> rootfs["encrypted block-COW RootFS"]
    rootfs --> object[("S3-compatible storage")]

Nomad schedules dedicated Sandbox0 nodes and resource-neutral carrier allocations. On claim, manager and PostgreSQL atomically select a ready slot and lease exact node CPU and memory. ctld creates the dynamic cgroup and prepares RootFS and network state; the task driver then writes the committed lease into the OCI spec and starts stock runsc.

CPU and memory are deliberately absent from the warm-slot compatibility key. Compatibility classes contain only immutable execution properties such as architecture, runsc version and platform, DirectFS/file-access mode, RootFS format, and security class.

State Durable? Location
Running processes, memory, sockets No Current gVisor runtime allocation
Writable RootFS Yes, after a committed checkpoint Encrypted regional S3-compatible storage
Named RootFS snapshot Yes Immutable block-COW generation
Lifecycle, capacity leases, policy, and metering producer state Yes Regional PostgreSQL
Historical metering read model Rebuildable ClickHouse projection from the PostgreSQL outbox

Pause checkpoints the exact writable RootFS and releases runtime compute. Resume creates a new runtime generation for the same sandbox identity. Live processes, memory, and sockets are intentionally not checkpointed.

Self-Hosted Architecture

Sandbox0 separates region-scoped control services from cluster-scoped data planes. One region may contain several data-plane clusters that share the region's PostgreSQL and S3 authorities.

Layer Components Responsibility
Region control plane regional-gateway, optional scheduler Identity, routing, template authority, and multi-cluster selection
Data-plane control cluster-gateway, manager, ssh-gateway Sandbox APIs, lifecycle, RootFS metadata, and node authority
Dedicated Nomad nodes ctld-a, ctld-b, nomad-driver-sandbox0, stock runsc Capacity, cgroups, RootFS, network policy, runtime creation, and terminal proof
Sandbox runtime procd inside runsc Commands, REPL contexts, files, services, and events
Regional stores PostgreSQL, S3-compatible object storage, optional ClickHouse Transactional truth, encrypted RootFS, and metering query projection

Self-hosting uses direct host services or Nomad service jobs for control services and direct systemd units for node-local ctld A/B. Start with deploy/nomad/README.md.

Repository Boundary

This repository contains the Sandbox0 control services, Nomad task driver, node runtime, public API contract, metering producer, deployment assets, and docs. Billing, pricing, invoices, and payments belong outside this repository.

Related repositories:

pkg/apispec/openapi.yaml is the only OpenAPI source of truth. Generated code and SDK copies must be synchronized from it rather than edited by hand.

Known Boundaries

  • Sandbox0 is a runtime boundary, not an agent framework.
  • Pause/resume preserves durable RootFS state, not processes, sockets, or memory.
  • Production nodes must be dedicated to Sandbox0. Nomad carrier resources cover driver overhead only and are not sandbox CPU or memory limits.
  • Production acceptance requires truthful physical capacity, multi-node failure tests, and security gates. Do not report a narrower local run as an eight-way production result.
  • Browser and computer-use workloads need templates that include their runtime dependencies.
  • Do not hand-edit generated OpenAPI or SDK output.

Contributing

Bug reports should include a minimal reproduction, relevant logs, Sandbox0 version or topology, and whether the deployment is Cloud or self-hosted. Remove API keys, tokens, private endpoints, customer data, and credentials before sharing logs.

Sandbox0 is Apache-2.0 licensed. See LICENSE.

Directories

Path Synopsis
cluster-gateway
ctld
cmd/ctld command
internal/ctld/networking/model
Package model defines runtime-neutral inputs to the node network policy compiler.
Package model defines runtime-neutral inputs to the node network policy compiler.
internal/ctld/server
Package server exposes ctld process health and Prometheus metrics.
Package server exposes ctld process health and Prometheus metrics.
global-gateway
pkg/memcache
Package memcache provides a thread-safe, bounded in-memory cache with TTL and LRU eviction.
Package memcache provides a thread-safe, bounded in-memory cache with TTL and LRU eviction.
internal
soakstate
Package soakstate provides a durable, hash-chained checkpoint log for opt-in endurance gates.
Package soakstate provides a durable, hash-chained checkpoint log for opt-in endurance gates.
manager
cmd/manager command
cmd/procd command
Package main is the entry point for the Procd service.
Package main is the entry point for the Procd service.
pkg/appservice
Package appservice owns manager-side sandbox application-service validation.
Package appservice owns manager-side sandbox application-service validation.
pkg/credentialbinding
Package credentialbinding converts and fingerprints credential binding policy without resolving secret-bearing source versions.
Package credentialbinding converts and fingerprints credential binding policy without resolving secret-bearing source versions.
pkg/eventbase
Package eventbase constructs manager-owned pubsub event metadata.
Package eventbase constructs manager-owned pubsub event metadata.
pkg/nodeauth
Package nodeauth defines the authenticated node identity shared by internal data-plane authority handlers.
Package nodeauth defines the authenticated node identity shared by internal data-plane authority handlers.
pkg/nodeauthority
Package nodeauthority assembles the manager's dedicated mTLS node listener.
Package nodeauthority assembles the manager's dedicated mTLS node listener.
pkg/nodepoolautoscaler
Package nodepoolautoscaler reconciles regional Sandbox0 capacity to one fixed worker plus a bounded provider-managed elastic pool.
Package nodepoolautoscaler reconciles regional Sandbox0 capacity to one fixed worker plus a bounded provider-managed elastic pool.
pkg/nomadclaim
Package nomadclaim implements the runtime-neutral manager claim API over region-authoritative Nomad warm slots.
Package nomadclaim implements the runtime-neutral manager claim API over region-authoritative Nomad warm slots.
pkg/retryqueue
Package retryqueue contains small mechanics shared by manager durable retry queues.
Package retryqueue contains small mechanics shared by manager durable retry queues.
pkg/rootfsimportdiscovery
Package rootfsimportdiscovery discovers ready image templates and idempotently creates their durable OCI-to-block import operations.
Package rootfsimportdiscovery discovers ready image templates and idempotently creates their durable OCI-to-block import operations.
pkg/rootfsimportworker
Package rootfsimportworker converts durable OCI import operations into attested immutable RootFS base artifacts.
Package rootfsimportworker converts durable OCI import operations into attested immutable RootFS base artifacts.
pkg/rootfsmaintenance
Package rootfsmaintenance owns background rootfs metadata and object-store reconciliation.
Package rootfsmaintenance owns background rootfs metadata and object-store reconciliation.
pkg/runtimeslotauthority
Package runtimeslotauthority serves the authenticated node-to-region warm runtime slot protocol.
Package runtimeslotauthority serves the authenticated node-to-region warm runtime slot protocol.
pkg/runtimeslotclaim
Package runtimeslotclaim plans and executes the region-authoritative warm Nomad slot claim path without assuming that manager can dial node-local Unix sockets directly.
Package runtimeslotclaim plans and executes the region-authoritative warm Nomad slot claim path without assuming that manager can dial node-local Unix sockets directly.
pkg/runtimeslotnode
Package runtimeslotnode adapts authenticated region-to-node dispatch to the runtime slot terminal reconciler.
Package runtimeslotnode adapts authenticated region-to-node dispatch to the runtime slot terminal reconciler.
pkg/runtimeslotnomad
Package runtimeslotnomad implements plugin-independent Nomad allocation retirement for the runtime-slot reconciler.
Package runtimeslotnomad implements plugin-independent Nomad allocation retirement for the runtime-slot reconciler.
pkg/runtimeslotreconciler
Package runtimeslotreconciler terminally cleans expired and orphaned Nomad runtime slots without depending on the task driver plugin process.
Package runtimeslotreconciler terminally cleans expired and orphaned Nomad runtime slots without depending on the task driver plugin process.
pkg/runtimeslotterminal
Package runtimeslotterminal assembles the plugin-independent regional runtime slot terminal worker.
Package runtimeslotterminal assembles the plugin-independent regional runtime slot terminal worker.
pkg/runtimeslotwriter
Package runtimeslotwriter adapts regional RootFS writer authority to the plugin-independent runtime slot terminal reconciler.
Package runtimeslotwriter adapts regional RootFS writer authority to the plugin-independent runtime slot terminal reconciler.
pkg/sandboxclaimreconciler
Package sandboxclaimreconciler completes durable Nomad claim cleanup after explicit deletion or abandoned admission.
Package sandboxclaimreconciler completes durable Nomad claim cleanup after explicit deletion or abandoned admission.
pkg/sandboxobservability
Package sandboxobservability contains manager-owned observability producers.
Package sandboxobservability contains manager-owned observability producers.
pkg/sandboxstore
Package sandboxstore owns durable sandbox identity and rootfs persistence.
Package sandboxstore owns durable sandbox identity and rootfs persistence.
procd/pkg/context
Package context provides context management for Procd.
Package context provides context management for Procd.
procd/pkg/file
Package file provides file system operations for Procd.
Package file provides file system operations for Procd.
procd/pkg/http
Package http provides the HTTP server for Procd.
Package http provides the HTTP server for Procd.
procd/pkg/http/handlers
Package handlers provides HTTP handlers for Procd.
Package handlers provides HTTP handlers for Procd.
procd/pkg/process
Package process provides process management for Procd.
Package process provides process management for Procd.
procd/pkg/process/cmd
Package cmd provides one-time command execution.
Package cmd provides one-time command execution.
procd/pkg/process/repl
Package repl provides configurable REPL process implementations.
Package repl provides configurable REPL process implementations.
procd/pkg/reaper
Package reaper removes orphaned zombie processes adopted by procd as PID 1.
Package reaper removes orphaned zombie processes adopted by procd as PID 1.
procd/pkg/session
Package session supervises durable, process-backed execution sessions.
Package session supervises durable, process-backed execution sessions.
pkg
apierror
Package apierror defines transport-neutral error categories shared by HTTP handlers and runtime services.
Package apierror defines transport-neutral error categories shared by HTTP handlers and runtime services.
apispec
Package apispec provides primitives to interact with the openapi HTTP API.
Package apispec provides primitives to interact with the openapi HTTP API.
clock
Package clock provides a synchronized clock across multiple clusters by periodically syncing with a shared PostgreSQL database.
Package clock provides a synchronized clock across multiple clusters by periodically syncing with a shared PostgreSQL database.
gateway/meteringbackend
Package meteringbackend initializes the shared gateway metering read model.
Package meteringbackend initializes the shared gateway metering read model.
internalauth
Package internalauth provides internal token-based authentication for inter-service communication within the sandbox0 infrastructure.
Package internalauth provides internal token-based authentication for inter-service communication within the sandbox0 infrastructure.
migrate
Package migrate provides a universal database migration solution for sandbox0 services.
Package migrate provides a universal database migration solution for sandbox0 services.
nodebootstrap
Package nodebootstrap installs and renews disposable Nomad sandbox workers.
Package nodebootstrap installs and renews disposable Nomad sandbox workers.
nomadruntime
Package nomadruntime owns the privileged Nomad node runtime hosted by ctld.
Package nomadruntime owns the privileged Nomad node runtime hosted by ctld.
observability
Package observability provides shared tracing, Prometheus metrics, and structured logging for Sandbox0 services.
Package observability provides shared tracing, Prometheus metrics, and structured logging for Sandbox0 services.
observability/httpserver
Package httpserver instruments net/http servers without importing a web framework.
Package httpserver instruments net/http servers without importing a web framework.
observability/internal/httpattrs
Package httpattrs contains shared HTTP semantic-convention helpers.
Package httpattrs contains shared HTTP semantic-convention helpers.
ocirootfs
Package ocirootfs resolves and safely applies one digest-pinned OCI image for production RootFS base artifact construction.
Package ocirootfs resolves and safely applies one digest-pinned OCI image for production RootFS base artifact construction.
procdapi
Package procdapi defines the manager-side contract for procd HTTP APIs.
Package procdapi defines the manager-side contract for procd HTTP APIs.
procdconfig
Package procdconfig defines the lightweight runtime configuration shared by procd and the components that inject its environment variables.
Package procdconfig defines the lightweight runtime configuration shared by procd and the components that inject its environment variables.
quantity
Package quantity parses the bounded CPU and byte quantities used by the runtime-neutral sandbox API.
Package quantity parses the bounded CPU and byte quantities used by the runtime-neutral sandbox API.
rediscache
Package rediscache provides shared Redis client and cache helpers.
Package rediscache provides shared Redis client and cache helpers.
rootfsblock
Package rootfsblock defines the bounded, versioned control descriptor for a durable RootFS block-map generation.
Package rootfsblock defines the bounded, versioned control descriptor for a durable RootFS block-map generation.
rootfsimporter
Package rootfsimporter builds immutable block artifacts from verified OCI images without owning regional operation or ready-artifact state.
Package rootfsimporter builds immutable block artifacts from verified OCI images without owning regional operation or ready-artifact state.
rootfsobjectstore
Package rootfsobjectstore constructs the regional RootFS object store from the shared manager/ctld configuration, including optional envelope encryption.
Package rootfsobjectstore constructs the regional RootFS object store from the shared manager/ctld configuration, including optional envelope encryption.
rootfsrebase
Package rootfsrebase provides the privileged, offline filesystem metadata and extent primitives used by the RootFS three-way rebase worker.
Package rootfsrebase provides the privileged, offline filesystem metadata and extent primitives used by the RootFS three-way rebase worker.
rootfswriterauthority
Package rootfswriterauthority defines the authenticated node-to-manager protocol used to consume, renew, and prove terminal state for a regional RootFS writer grant.
Package rootfswriterauthority defines the authenticated node-to-manager protocol used to consume, renew, and prove terminal state for a regional RootFS writer grant.
runtimecontrol
Package runtimecontrol defines the immutable runtime assignment shared by manager, the Nomad driver, and procd.
Package runtimecontrol defines the immutable runtime assignment shared by manager, the Nomad driver, and procd.
runtimeslot
Package runtimeslot defines the versioned node-to-region protocol for generic warm runtime allocations.
Package runtimeslot defines the versioned node-to-region protocol for generic warm runtime allocations.
sandboxobservability
Package sandboxobservability defines the per-sandbox historical event, log, and metric query contract.
Package sandboxobservability defines the per-sandbox historical event, log, and metric query contract.
sandboxobservability/clickhouse
Package clickhouse implements the ClickHouse query backend for per-sandbox historical observability events, logs, and metric samples.
Package clickhouse implements the ClickHouse query backend for per-sandbox historical observability events, logs, and metric samples.
sandboxspec
Package sandboxspec defines runtime-neutral sandbox template and network policy data.
Package sandboxspec defines runtime-neutral sandbox template and network policy data.
streaming
Package streaming provides transport helpers for long-lived HTTP streams.
Package streaming provides transport helpers for long-lived HTTP streams.
tokenbucket
Package tokenbucket provides shared local and Redis-backed token buckets for request admission and byte-rate backpressure.
Package tokenbucket provides shared local and Redis-backed token buckets for request admission and byte-rate backpressure.
regional-gateway
scheduler
cmd/scheduler command
scripts
license-sign command
ssh-gateway
cmd/ssh-gateway command
tests
tools
node-bootstrap command
rootfs-materializer-soak command
Command rootfs-materializer-soak runs the opt-in, active-time acceptance gate for PostgreSQL-backed RootFS materialization against a real RustFS.
Command rootfs-materializer-soak runs the opt-in, active-time acceptance gate for PostgreSQL-backed RootFS materialization against a real RustFS.
runtime-slot-slo command
Command runtime-slot-slo validates the public regional claim route against the trusted ingress-to-procd timer emitted by the Nomad manager backend.
Command runtime-slot-slo validates the public regional claim route against the trusted ingress-to-procd timer emitted by the Nomad manager backend.
soak-evidence-verify command
Command soak-evidence-verify independently audits completed production endurance evidence against the fixed materializer or Bolt acceptance contract.
Command soak-evidence-verify independently audits completed production endurance evidence against the fixed materializer or Bolt acceptance contract.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL