Skip to content

Kits and sandbox specs

What a sandbox holds when it starts comes from its kit; everything else it receives, from its mounts to its keys, can be described with it in a sandbox spec. This page explains both, and what is kept between sandboxes. The guides show them in use: Kits and mixins and Sandbox specs.

direction: down
base: "Base kit\nshell, claude, codex…"
mixins: "Mixins\nfiles, install commands,\nvariables, hosts, MCP servers"
comp: "Composition\nKit(base, mixins)"
pkg: "Kit package\ncreation request and images"
cache: "Kit cache\nmemory or directory" {shape: cylinder}
spec: "Sandbox spec\nkit, mounts, rules, keys,\nMCP servers, variables, resources" {shape: page}
sandbox: Sandbox {style.multiple: true}
base -> comp
mixins -> comp
comp -> pkg: "forged by fastsandbox,\nor compiled by sbx"
pkg -> cache: kept by {style.stroke-dash: 3}
spec -> sandbox: launch
pkg -> sandbox

Kits

A base kit is a published environment: shell, a plain Linux system, or the kit of a coding agent, named after it (claude, codex…). A mixin adds to a base kit: files, install commands, variables, allowed hosts, MCP servers. A Kit is a composition of one base kit and its mixins; a plain name such as "shell" is a kit with no mixin. Mixins come from a directory, as the sbx command line reads them, or are written in Python.

The daemon does not resolve a kit by itself. It creates a sandbox from a kit package: the creation request the sbx command line would send for the kit, and the images it needs.

Forged or compiled

There are two ways to make a package:

Forged (the default) Compiled
By fastsandbox, through the socket of the daemon The sbx command line, run once on a throw-away sandbox
Needs The daemon The daemon and the sbx command line
Takes Published base kits, mixins of a directory or written in Python Any kit sbx create takes, a local kit directory or a Git repository included
Asked with Nothing: kit="shell" KitCache(sbx="sbx")

A kit only sbx resolves raises KitForgeError or InvalidKitError with the default cache; see Compiling with the CLI.

What is kept, and for how long

What Where Kept until
The package of a composition The kit cache of the client: in memory by default, or in a directory given as KitCache(directory) or FASTSANDBOX_KIT_CACHE The process ends, for the memory; you empty the directory, for a directory
The images of a kit The image store of the daemon: the published image of the base kit, and the images the package loads into the daemon The base image stays until you remove it (Images); the daemon drops the tags of the images a package loads by itself, some minutes after their last sandbox, and the package loads them again when needed

A kept package is used again for the same composition, as long as it suits the daemon (KitPackage.suits()): forged by the same version of the docker-sandbox crates, which a release of fastsandbox pins, for the API version the daemon speaks; a package compiled by sbx, by the same version of sbx. A mixin whose descriptor or spec.yaml changed is a new composition, forged again.

A cache is not a lock

The cache does not see a base kit that moved since its package was made, such as a newer image published under the same tag: the package kept stays in use until you call KitCache.refresh(client, kit) or empty the directory. Two machines, or two runs a week apart, can therefore build their sandboxes from different images of the same kit. To launch from the same package every time, save it (KitPackage.save(dir)) and launch on that directory, for as long as it suits the daemon.

Sandbox specs

A SandboxSpec describes everything a sandbox receives but its name and the values of its keys: its kit and mixins, its workspace and mounts, its host and HTTP rules, the API keys its proxy writes, the MCP servers of its agent, its variables and its resources. One spec serves every sandbox of a job, holds nothing secret, and has a JSON form for a program in another language.

  • check(client) applies the rules of a launch before anything is created: a host that is no host pattern, a refusal that covers the host of a key, mounts without a workspace, a variable set twice.
  • launch(client, name, keys) makes the same checks, forges the kit, creates the sandbox, applies its HTTP rules, pushes its keys and starts it, then returns a Lease, which owns the sandbox until it is shut down.
  • The host rules of a spec are forged into its kit as a mixin: the daemon creates them with the sandbox, so they hold from its creation. Its HTTP rules and its keys come before its start: its startup commands get them, its install commands do not.

FastSandbox launches the sandbox of every run of a task from a spec that the task and its inputs describe. See Sandbox lifecycle for what a lease removes.

Next

  • Kits and mixins: the cache, compositions, mixins written in Python, packages assembled by hand.
  • Sandbox specs: writing a spec, its keys, its JSON form, launching on a package.