Skip to content

Kits

fastsandbox.Kit

Bases: BaseModel

A kit to create sandboxes from: a base kit, mixins and kit arguments.

Attributes:

Name Type Description
base str

The base kit, as sbx create <kit> takes it: an agent sbx knows (shell, claude…), an image (a name with a slash, ghcr.io/acme/kit:1, or oci://…), a directory written as a path (./my-kit, /…, ~/…), or a Git repository (git+https://…). A name without a slash is an agent, whatever the working directory holds; only the sbx CLI builds a directory or a Git repository.

mixins tuple[str | Mixin, ...]

Mixin kits composed on top of the base, in order: directories, mixins written in Python (Mixin), or, for the CLI alone, images, ZIP files and Git repositories, as sbx create --kit takes them. A text without a slash names a directory of the working directory.

args dict[str, str]

Kit arguments, as sbx create --kit-arg takes them: the forge gives them to the base kit, and an argument may name its kit, as claude.model for the base kit claude; a mixin declares none.

label property

label: str

A readable name of the composition, e.g. shell+mixin@model=x.

of classmethod

of(kit: Kit | KitRef | str) -> Kit

kit as a composition: itself, or the base kit it names, without mixins.

fastsandbox.KitRef dataclass

KitRef(kind: Literal['agent', 'image', 'local', 'git', 'other'], value: str)

A kit, as the sbx CLI reads it from its name.

KitRef.base(text) reads a text as sbx create <text> reads its base kit, and KitRef.mixin(text) as sbx create --kit <text> reads a mixin, by the rules docker-sandbox-kit measured on the CLI.

Example

KitRef.base("claude") KitRef(kind='agent', value='claude') KitRef.base("ghcr.io/acme/kit:1").kind 'image'

Attributes:

Name Type Description
kind Literal['agent', 'image', 'local', 'git', 'other']

agent, an agent sbx knows, by its published kit; image, an image of a registry; local, a directory or a ZIP file of the host; git, a Git repository; other, a kind a newer crate reads.

value str

What names it: the agent, the image (without an oci:// prefix), the path (~ expanded) or the repository, as written.

agent property

agent: Agent | None

The agent the kit is, for an agent kit.

base classmethod

base(text: str) -> KitRef

The kit sbx create <text> takes as base kit.

A Git repository (git+https://…, git+ssh://…), an image (oci://…, or a name with a slash, even when a directory of that name exists), a path written as one (./…, ../…, /…, ~/…), and otherwise an agent.

Raises:

Type Description
InvalidKitError

For a name without a slash that is not an agent sbx knows, as the CLI refuses it, and for an empty text.

mixin classmethod

mixin(text: str) -> KitRef

The kit sbx create --kit <text> takes as mixin.

A Git repository, an image written oci://…, a path written as one, a path relative to the working directory that exists (tools, kits/tools), and otherwise an image when the name holds a slash.

Raises:

Type Description
InvalidKitError

For a name without a slash that names no directory, which the CLI takes neither for a path nor for an image, and for an empty text.

fastsandbox.KitPackage

KitPackage(native: KitPackage)

A kit package: forged without the sbx CLI, compiled by it, or opened from a directory.

A package forged in memory has no directory, and its images are held in memory.

native property

native: KitPackage

The handle of the native extension.

dir property

dir: Path | None

The directory of the package, None for a package held in memory.

compiled_with property

compiled_with: str | None

The sbx version the package was compiled with, None for a forged package.

compiled_api property

compiled_api: str | None

The daemon API version the package was forged or compiled for.

kit_refs property

kit_refs: list[str]

The kit references of the package, base kit first.

agent property

agent: KitAgent | None

The agent the base kit describes, if any.

kit_artifacts property

kit_artifacts: list[Any]

The kit artifacts, as the daemon receives them.

images property

images: list[PackageImage]

The image archives of the package, without their bytes (image_archive).

in_memory classmethod

in_memory(template: CreateRequest | Mapping[str, Any], images: Iterable[PackageImage], metadata: Mapping[str, Any] | None = None) -> KitPackage

A package assembled by hand, held in memory: a creation request and its images.

template is the creation request of every sandbox of the package, whose name {{name}} stands for the name of each one, as a forger of one's own assembles it (CreateRequest.for_agent, its kits and their artifacts). images hold their archives (PackageImage.in_memory), loaded under their reference when the daemon does not hold them yet. metadata is what kit.json holds besides, none by default.

Raises:

Type Description
ValueError

When an image holds no archive (one listed by a package rather than made with PackageImage.in_memory).

InvalidRequestError

When template or metadata is not a JSON object.

open classmethod

open(dir: str | PathLike[str]) -> KitPackage

Opens the package forged or compiled into dir.

Raises:

Type Description
KitPackageError

When dir holds no valid package.

suits

suits(client: Client) -> bool

Whether the package suits the daemon of client, which can create sandboxes from it.

A package compiled by the sbx CLI suits the daemon of the sbx version it was compiled with; a forged one, the daemon of the API it was forged for, forged by this version of the crates, which write their packages as they do. A package that records neither suits no daemon.

save

save(dir: str | PathLike[str]) -> KitPackage

Writes the package into dir, replacing a package already there.

A package forged in memory is kept that way for later processes, or given to whatever takes a package by its directory. Returns the package of dir.

Raises:

Type Description
KitPackageError

When the package cannot be written.

image_archive

image_archive(index: int) -> bytes

The archive of the image at index of images: held in memory, or of its file.

Raises:

Type Description
IndexError

When the package has no image at index.

HostFileError

When the file of the archive cannot be read.

request

request(name: str) -> CreateRequest

The creation request of a sandbox named name from this package.

load_images async

load_images(client: Client) -> int

Loads the images of the package into the daemon; returns how many.

create async

create(client: Client, name: str) -> Created

Loads the images and creates the sandbox name from the package.

create_with async

create_with(client: Client, request: CreateRequest) -> Created

Loads the images and creates a sandbox from an adjusted request.

request is the one request(name) gives, adjusted by the caller: a workspace, variables or ports added, for instance.

install_into async

install_into(sandbox: Sandbox) -> int

Installs the kits in place in a running sandbox.

Returns how many artifacts were installed.

add_to async

add_to(sandbox: Sandbox) -> SwapOutcome

Adds the kits to a sandbox by swapping its container.

fastsandbox.KitAgent

KitAgent(native: KitAgent)

The agent a kit describes: its program, run options and network needs.

native property

native: KitAgent

The handle of the native extension.

name property

name: str

The name of the agent, e.g. claude.

display_name property

display_name: str | None

The display name of the agent.

binary property

binary: str | None

The program of the agent.

run_options property

run_options: list[str]

The options the kit runs the agent with.

network property

network: list[str]

The network entries the kit declares.

from_artifact classmethod

from_artifact(artifact: Any) -> KitAgent | None

The agent described by a kit artifact, if it describes one.

command

command(*args: str) -> list[str]

The command line that runs the agent with args.

hosts

hosts() -> list[str]

The hosts the agent needs to reach.

fastsandbox.KitForge

KitForge(client: Client)

Forges kits into packages without the sbx CLI, through the socket alone.

The base kit is rebuilt from its published image, which the daemon pulls and exports; the mixins are read from their directories, whose spec.yaml is written in the JSON subset of YAML, or written in Python. Kit arguments are checked as the CLI checks them. A forged package suits the daemon it was forged for while the crates keep their version.

A forge for the daemon of client.

forge async

forge(kit: Kit | KitRef | str, output: str | PathLike[str] | None = None) -> KitPackage

Forges kit: in memory, or into the package directory output when given.

Raises:

Type Description
InvalidKitError

When a kit is not named as the CLI names one (a base kit without a slash that is not an agent, a mixin that names no directory), a mixin is one only the CLI resolves (an image, a ZIP file, a Git repository), or the forge refuses a descriptor or a kit argument.

KitForgeError

When the base kit is one only the sbx CLI builds (a directory, a Git repository), or the kit policy of the daemon forbids forging it.

HostFileError

When a mixin directory or its spec.yaml cannot be read.

check async

check(kit: Kit | KitRef | str) -> None

Checks kit before forging it, without pulling or writing anything.

The base kit, the arguments that name it and the kit policy of the daemon are checked; the arguments are checked against the descriptor of the base kit only when it is forged, as the descriptor comes with its image.

Raises:

Type Description
InvalidKitError

As forge does, for what can be told before forging.

KitForgeError

When the base kit is one only the CLI builds, or the kit policy of the daemon refuses the composition.

forge_over async

forge_over(package: KitPackage, mixins: Iterable[str | Mixin] = (), output: str | PathLike[str] | None = None) -> KitPackage

Forges mixins over every kit of package: in memory, or into output when given.

The package keeps its kits, its base kit and its own mixins with their artifacts and their images, and mixins come after them, given as text (a directory) or written in Python. A kit only the CLI resolves (a mixin given by image or Git, a local base kit), compiled once (KitCompiler, a KitCache that compiles), takes mixins forged in code all the same. A spec composes its own mixins over a package this way; a spec without mixins launches the package as it is, while this method needs at least one mixin.

Raises:

Type Description
InvalidKitError

When a mixin names no directory, is one only the CLI resolves, or the forge refuses its descriptor.

KitForgeError

When mixins is empty, or the kit policy of the daemon forbids forging it.

HostFileError

When a mixin directory or its spec.yaml cannot be read.

forge_over_base async

forge_over_base(package: KitPackage, mixins: Iterable[str | Mixin] = (), output: str | PathLike[str] | None = None) -> KitPackage

Forges mixins over the base kit of package alone: in memory, or into output.

The base kit is the first kit of the package, as it was forged or compiled, taken without pulling its image again; the other kits of the package and their images are left out, as forge_over would keep them. A package saved or compiled once is composed again this way with other mixins.

Raises:

Type Description
InvalidKitError

When a mixin names no directory, is one only the CLI resolves, or the forge refuses its descriptor.

KitForgeError

When mixins is empty, or the kit policy of the daemon forbids forging it.

HostFileError

When a mixin directory or its spec.yaml cannot be read.

fastsandbox.KitCompiler

KitCompiler(client: Client, *, sbx: str | PathLike[str] = 'sbx', work_dir: str | PathLike[str] | None = None, timeout: float | None = None)

Compiles kits into packages with the sbx CLI.

It runs the CLI once behind a capturing proxy, on a throw-away sandbox, sbx-kit-compile-<pid>-<n>, which it removes when the compilation ends or fails; a compilation cancelled, or a process killed, can leave it.

A compiler for the daemon of client.

Parameters:

Name Type Description Default
client Client

The client of the daemon.

required
sbx str | PathLike[str]

The sbx program, found on PATH by default.

'sbx'
work_dir str | PathLike[str] | None

Scratch directory of the compiler; a temporary one, removed after each compilation, by default.

None
timeout float | None

Deadline of a compilation, in seconds.

None

compile async

compile(base: str, output: str | PathLike[str], *, mixins: tuple[str | Mixin, ...] | list[str | Mixin] = (), args: dict[str, str] | None = None) -> KitPackage

Compiles a kit into the package directory output.

base is the base kit as sbx create takes it, composed with mixins, in the order given, and kit args. A mixin given as text goes to the CLI as it is (--kit); a mixin written in Python is written into a directory of the scratch directory, given to the CLI, and removed with it: the package lists it under the path of that directory, as the CLI lists a local kit.

Raises:

Type Description
KitCompileError

When the sbx CLI cannot compile the kit.

InvalidKitError

When the crate refuses a mixin written in Python.

SandboxTimeoutError

When the compilation runs over the deadline.

fastsandbox.KitCache

KitCache(directory: str | PathLike[str] | None = None, *, sbx: str | PathLike[str] | None = None, timeout: float | None = None)

Kit packages, made on first use and kept for the next sandboxes.

By default kits are forged without the sbx CLI (KitForge) and kept in memory for the process: nothing is written on the host, and a later process forges them again, in a few seconds once the daemon holds the image of the base kit. Given a directory, the cache keeps its packages there too, one directory per composition, for later processes. Given the sbx CLI, it compiles kits with it (KitCompiler), which can take a few minutes for an agent kit, into its directory.

A composition is its base kit, its arguments and its mixins, the text of the spec.yaml of a mixin directory and the descriptor of a mixin written in Python included: a mixin changed is made again. A package is used again while it suits the daemon (KitPackage.suits): one compiled by the CLI for the sbx version it runs, one forged by this version of the crates for the API it speaks. The packages the CLI compiles are kept apart from those forged. Each composition is made by one caller at a time, whatever their event loops.

Attributes:

Name Type Description
directory

The directory the packages are kept in, None for a cache that keeps them in the memory of the process alone.

A cache in memory, or in directory, compiling with the sbx program sbx if given.

Parameters:

Name Type Description Default
directory str | PathLike[str] | None

Where packages are kept; $FASTSANDBOX_KIT_CACHE when not given, else the memory of the process, or default_cache_dir() for a cache that compiles with the CLI.

None
sbx str | PathLike[str] | None

The sbx program to compile kits with, e.g. "sbx"; kits are forged without the CLI when not given.

None
timeout float | None

Deadline of a compilation by the CLI, in seconds.

None

compiles property

compiles: bool

Whether the cache compiles its kits with the sbx CLI, rather than forging them.

native property

native: KitCache

The handle of the native extension.

default classmethod

default() -> KitCache

The kit cache of the process, shared by the clients given none.

One per value of $FASTSANDBOX_KIT_CACHE, so that a change of it takes effect.

package async

package(client: Client, kit: Kit | str) -> KitPackage

The package of kit for the daemon of client, made now unless one kept suits it.

Raises:

Type Description
InvalidKitError

When a kit is not named as the CLI names one, or the forge refuses a mixin, a descriptor or a kit argument.

KitForgeError

When the kit is one only the sbx CLI builds, for a cache that forges.

HostFileError

When a mixin directory cannot be read, for a cache that forges.

KitCompileError

When the sbx CLI cannot compile the kit, for a cache that compiles.

refresh async

refresh(client: Client, kit: Kit | str) -> KitPackage

The package of kit, made again in place of the one kept.

For a base kit of a registry or a Git repository that moved since it was made, which the cache does not see by itself.

Raises:

Type Description
InvalidKitError

As package does.

KitForgeError

As package does.

HostFileError

As package does.

KitCompileError

As package does.

fastsandbox.kits.default_cache_dir

default_cache_dir() -> Path

The default directory of the kit cache.

$FASTSANDBOX_KIT_CACHE, else $XDG_CACHE_HOME/fastsandbox/kits, else ~/.cache/fastsandbox/kits.

Mixins written in Python

fastsandbox.Mixin

Bases: BaseModel

A mixin written in Python: a descriptor, listed under a reference.

The crate checks it when it is made, as the forge checks the mixins it reads from their directories: the hosts of its rules, its commands, the fields it names. Kit.mixins takes it as it takes a directory; the forge sends it to the daemon as it is, and the compiler writes it into a directory of its own for the CLI. save() writes it into a directory of one's choice, as the CLI reads a local kit.

Attributes:

Name Type Description
reference str

A path, as the CLI lists a local kit, whose last part names the mixin, e.g. /kits/acme-tools. The daemon finds the mixin by its image, so the path need not exist.

descriptor KitDescriptor

What the mixin declares.

Raises:

Type Description
InvalidKitError

When the forge would refuse the mixin.

name property

name: str

The name of the mixin, the last part of its reference.

read classmethod

read(directory: str | PathLike[str]) -> Mixin

The mixin of directory, described by its spec.yaml written in JSON.

It is listed under the canonical path of the directory.

Raises:

Type Description
InvalidKitError

When the forge would refuse its descriptor.

HostFileError

When the directory or its spec.yaml cannot be read.

from_ref classmethod

from_ref(text: str | KitRef) -> Mixin

The mixin text names, read as sbx create --kit reads it: a directory.

A path written as one (./tools, /…, ~/…), or a name of a directory of the working directory (tools), is read from its spec.yaml; a KitRef.mixin of a directory too.

Raises:

Type Description
InvalidKitError

For a text that names no directory, or an image, a ZIP file or a Git repository, which only the CLI resolves.

HostFileError

When the directory or its spec.yaml cannot be read.

save

save(directory: str | PathLike[str]) -> Mixin

Writes the mixin into directory, created if needed, as the CLI reads a local kit.

Its spec.yaml holds the descriptor in JSON behind its # syntax= line. Returns the mixin of that directory, named after it and listed under its canonical path, as the CLI lists the kit in the packages it compiles.

Raises:

Type Description
HostFileError

When the directory or its spec.yaml cannot be written.

to_json

to_json() -> dict[str, Any]

The mixin as JSON, its reference and its descriptor, the form the crate reads.

mcp classmethod

mcp(agent: Agent | str, *servers: McpServer) -> Mixin

The mixin that registers servers in the configuration of the agent agent.

Built by the crate, for claude, copilot and opencode. Its install commands register the servers inside the sandbox, as the user agent, as the kit of the agent registers its MCP gateway (claude mcp add for claude), and it allows the hosts of those reached at a URL. The tokens are not part of it: they are given at creation, in the variables token_env of the servers (McpServer.env()), which the agent reads when it connects, so that one package serves sandboxes with tokens of their own. Its reference is /kits/docker-sandbox-mcp-<agent>.

Raises:

Type Description
InvalidKitError

For an agent without an MCP adapter, no server, two servers of the same name, a name or a variable that is not one, a URL that is not an http or https one or holds a character a shell command cannot carry, a stdio server without a program or given a token, or a server reached at a URL given arguments.

fastsandbox.KitDescriptor

Bases: _Spec

The v3 descriptor of a mixin, the spec.yaml of the kit.

Build one with KitDescriptor.mixin() and the with_* methods, or read one with parse(), read() or from_json(), which the crate checks as the forge does.

Attributes:

Name Type Description
schema_version Literal['3']

Version of the descriptor format, 3.

kind Literal['mixin']

Kind of kit, mixin.

display_name str | None

Name shown for the kit.

description str | None

What the kit is for.

version str | None

Version of the kit, e.g. 1.0.0.

author Any

Author of the kit, kept as written.

licenses Any

Licenses of the kit, kept as written.

source_url str | None

Where the kit comes from.

capabilities tuple[Capability, ...]

What the kit declares, in order.

mixin classmethod

mixin(display_name: str) -> KitDescriptor

An empty mixin named display_name, to build on with the with_* methods.

parse classmethod

parse(text: str) -> KitDescriptor

The descriptor of the text of a spec.yaml written in JSON.

The comment and blank lines that open it, such as its # syntax= line, are skipped.

Raises:

Type Description
InvalidKitError

When the rest is not JSON, or not a v3 mixin the forge takes.

read classmethod

read(path: str | PathLike[str]) -> KitDescriptor

The descriptor in the spec.yaml at path.

Raises:

Type Description
OSError

When the file cannot be read.

InvalidKitError

As parse() does.

from_json classmethod

from_json(value: dict[str, Any]) -> KitDescriptor

The descriptor of its JSON, as spec.yaml holds it.

Raises:

Type Description
InvalidKitError

When it is not a v3 mixin the forge takes.

with_description

with_description(description: str) -> KitDescriptor

The descriptor, with the description description.

with_version

with_version(version: str) -> KitDescriptor

The descriptor, with the kit version version, e.g. 1.0.0.

with_install

with_install(step: LifecycleStep) -> KitDescriptor

The descriptor, with a command run once, when the sandbox is created.

with_startup

with_startup(step: LifecycleStep) -> KitDescriptor

The descriptor, with a command run at every start of the sandbox.

with_network_allow

with_network_allow(*hosts: str) -> KitDescriptor

The descriptor, allowing hosts while the sandbox runs.

A host is host, *.domain, host:port, a CIDR prefix…, as the CLI takes it; the crate checks the hosts when the mixin is made.

with_network_deny

with_network_deny(*hosts: str) -> KitDescriptor

The descriptor, denying hosts while the sandbox runs.

A deny wins over any allow, of the sandbox or of its kits.

to_json

to_json() -> dict[str, Any]

The descriptor as JSON, as spec.yaml holds it.

to_spec

to_spec() -> str

The text of a spec.yaml holding the descriptor.

Its # syntax= line, then the descriptor as JSON, which the sbx CLI reads as YAML.

fastsandbox.LifecycleStep

Bases: _Spec

A command a mixin runs: once, when the sandbox is created, or at each of its starts.

Attributes:

Name Type Description
command str | tuple[str, ...]

A shell command, run with sh -c, or a program and its arguments.

user str | None

The user it runs as, e.g. agent, or 0 for root.

description str | None

What it does, shown as it runs.

env tuple[str, ...]

The variables of the sandbox it receives: an install command runs in an emptied environment otherwise, which keeps only PATH, HOME, USER, TERM and the proxy and certificate variables.

background bool | None

Whether a startup command runs in the background.

as_user

as_user(user: str) -> LifecycleStep

The step, run as user, e.g. agent, or 0 for root.

with_description

with_description(description: str) -> LifecycleStep

The step, described by description.

with_env

with_env(*names: str) -> LifecycleStep

The step, given the variables names of the sandbox too.

with_gateway_env

with_gateway_env() -> LifecycleStep

The step, given the MCP gateway of the sandbox: GATEWAY_ENV.

in_background

in_background() -> LifecycleStep

The startup step, run in the background.

fastsandbox.kits.LifecycleCapability

Bases: _Spec

The install and startup commands of a kit (com.docker.sandbox/lifecycle@1).

Attributes:

Name Type Description
type Literal['com.docker.sandbox/lifecycle@1']

LIFECYCLE.

name str | None

Name of the capability.

description str | None

What the capability does.

optional bool | None

Whether the kit works without it.

config LifecycleConfig

The commands.

fastsandbox.kits.LifecycleConfig

Bases: _Spec

The commands of a lifecycle capability.

Attributes:

Name Type Description
install tuple[LifecycleStep, ...]

Commands run once, when the sandbox is created, before its agent starts.

startup tuple[LifecycleStep, ...]

Commands run at every start of the sandbox, alongside its agent.

fastsandbox.kits.NetworkCapability

Bases: _Spec

The network rules of a kit (com.docker.sandbox/network-policy@1).

Attributes:

Name Type Description
type Literal['com.docker.sandbox/network-policy@1']

NETWORK.

name str | None

Name of the capability.

description str | None

What the capability does.

optional bool | None

Whether the kit works without it.

config NetworkConfig

The rules.

fastsandbox.kits.NetworkConfig

Bases: _Spec

The rules of a network capability.

Attributes:

Name Type Description
runtime NetworkRules

Rules while the sandbox runs.

install NetworkRules

Hosts allowed while the install commands run.

fastsandbox.kits.NetworkRules

Bases: _Spec

Hosts allowed and denied, each host, *.domain, host:port or a CIDR prefix.

Attributes:

Name Type Description
allow tuple[str, ...]

Hosts allowed.

deny tuple[str, ...]

Hosts denied; a deny wins over any allow, of the sandbox or of its kits.

fastsandbox.kits.Capability module-attribute

Capability = Annotated[LifecycleCapability | NetworkCapability, Field(discriminator='type')]

A capability a mixin declares, told apart by its type.

fastsandbox.kits.LIFECYCLE module-attribute

LIFECYCLE: Final = 'com.docker.sandbox/lifecycle@1'

The type of the capability of install and startup commands.

fastsandbox.kits.NETWORK module-attribute

NETWORK: Final = 'com.docker.sandbox/network-policy@1'

The type of the capability of network rules.

fastsandbox.kits.GATEWAY_ENV module-attribute

GATEWAY_ENV = ('MCP_GATEWAY_URL', 'MCP_SENTINEL_TOKEN_NAME')

The variables of a sandbox that name its MCP gateway: its address, and the bearer token the kits of the agents send it.

The MCP servers of an agent

fastsandbox.McpServer

Bases: BaseModel

An MCP server for the agent of a sandbox, registered by Mixin.mcp().

Make one with McpServer.host(), McpServer.remote() or McpServer.stdio(), as the crate makes them; Mixin.mcp() checks it. to_json() is its JSON form, as a sandbox spec holds it, and from_json() reads one.

Attributes:

Name Type Description
kind Literal['host', 'remote', 'stdio']

host, a server a process of the host serves; remote, a server the agent calls over the network; stdio, a program the agent starts in the sandbox.

name str

The name the agent knows the server under: letters, digits, - and _.

url str | None

The URL of its endpoint, over streamable HTTP; None for a stdio server.

token_env str | None

The variable of the sandbox holding its bearer token, if it takes one.

port int | None

The port of the loopback of the host it listens on, for a server of the host.

command tuple[str, ...]

The program of a stdio server and its arguments.

host classmethod

host(name: str, port: int) -> McpServer

A server a process of the host serves on port of its loopback, in any language.

The sandbox reaches it at http://host.docker.internal:<port>/mcp; its proxy forwards the requests to the loopback of the host as localhost:<port>, so a server guarded against DNS rebinding takes them as it takes those of the host. Its bearer token is read from the variable token_env, DOCKER_SANDBOX_MCP_<NAME>_TOKEN, which the creation request sets (env(token)) and the server checks: the token, not the origin of a request, tells the sandbox apart from the other processes of the host. The proxy writes no secret into the requests to the host: the sandbox holds that token, which is to be random and its own.

remote classmethod

remote(name: str, url: str) -> McpServer

A remote server at url, called by the agent itself.

It takes no token until with_bearer_env().

stdio classmethod

stdio(name: str, program: str) -> McpServer

A server the agent starts inside the sandbox, as the user agent.

The agent speaks to it over its standard input and output: program, a path or a name the PATH of the sandbox finds, with the arguments of with_args(). It inherits the environment of the sandbox, whose variables give it its secrets. Installing the program is the work of another mixin, or of the image of the kit. It takes no token.

from_json classmethod

from_json(form: dict[str, Any]) -> McpServer

The server of its JSON form, e.g. {"kind": "host", "name": "tools", "port": 47813}.

Raises:

Type Description
ValueError

When the form is not one of an MCP server.

with_args

with_args(*args: str) -> McpServer

The stdio server, its program given args after those it has.

A server reached at a URL takes none: Mixin.mcp() refuses it.

with_bearer_env

with_bearer_env(env: str) -> McpServer

The server, sent the content of the variable env of the sandbox as its bearer token.

For a key the sandbox must not hold, give the sandbox a ProxiedKey read from env for the host of the server, or a key of its spec (KeySpec.for_hosts): the variable holds its placeholder, which the proxy replaces with the key. A stdio server takes none: Mixin.mcp() refuses it.

env

env(token: str) -> dict[str, str]

The variables of a creation request that give the server its bearer token token.

Raises:

Type Description
ValueError

When the server takes no token.

to_json

to_json() -> dict[str, Any]

The JSON form of the server, as a sandbox spec holds it.

Raises:

Type Description
InvalidKitError

For a server no JSON form describes: a stdio server given a token, or a server reached at a URL given arguments.