Skip to content

Agents

fastsandbox.Agent

Bases: StrEnum

An agent sbx knows, run by the published kit of its name, docker.io/sbx/<name>:latest.

Its value is its name, as sbx create <name> takes it: Agent("claude") reads it.

CLAUDE class-attribute instance-attribute

CLAUDE = 'claude'

Claude Code.

CODEX class-attribute instance-attribute

CODEX = 'codex'

Codex.

COPILOT class-attribute instance-attribute

COPILOT = 'copilot'

GitHub Copilot.

CURSOR class-attribute instance-attribute

CURSOR = 'cursor'

Cursor.

DEVIN class-attribute instance-attribute

DEVIN = 'devin'

Devin.

DOCKER_AGENT class-attribute instance-attribute

DOCKER_AGENT = 'docker-agent'

Docker Agent.

DROID class-attribute instance-attribute

DROID = 'droid'

Droid.

KIRO class-attribute instance-attribute

KIRO = 'kiro'

Kiro.

OPENCODE class-attribute instance-attribute

OPENCODE = 'opencode'

OpenCode.

SHELL class-attribute instance-attribute

SHELL = 'shell'

A plain shell: no agent, the base of other kits.

keys property

keys: tuple[AgentKey, ...]

The API keys the agent takes, by the service of the kits.

Each goes to the proxy, its value read from the first of its variables the program has. Empty for shell, and for kiro, which sbx knows no service for (forwarded_env).

forwarded_env property

forwarded_env: tuple[str, ...]

The variables the agent reads a key from that sbx knows no service for.

They go into the sandbox as they are, so their values are visible inside it: KIRO_API_KEY for kiro, none for the others.

headless

headless(kit_agent: KitAgent, prompt: str) -> Headless | None

How the agent runs prompt without a terminal, and exits.

Its program and the options of its sessions come from kit_agent, the agent its kit declares (KitPackage.agent). None for shell, and for a kit that declares no program for an agent whose command starts with the options of its sessions.

fastsandbox.AgentKey dataclass

AgentKey(service: str, env: tuple[str, ...])

An API key an agent takes.

Attributes:

Name Type Description
service str

The service of the key, as the kits and sbx secret set name it, e.g. anthropic.

env tuple[str, ...]

The variables the agent reads the key from, in order of preference.

fastsandbox.Headless dataclass

Headless(command: tuple[str, ...], output: Literal['jsonl', 'text'])

How an agent runs one prompt without a terminal, and exits.

Attributes:

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

The command, the prompt included, to run in the sandbox.

output Literal['jsonl', 'text']

What it writes on its standard output: one JSON event per line (jsonl), or text for a person (text).

fastsandbox.AgentRunner

AgentRunner(sandbox: Sandbox, agent: Agent, kit_agent: KitAgent)

Runs the agent of the sandbox of a task: one prompt unattended, or an interactive session.

Attributes:

Name Type Description
sandbox

The sandbox of the task.

agent

The agent, e.g. Agent.CLAUDE.

kit_agent

The agent its kit declares: its program and the options of its sessions.

name property

name: str

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

command

command(prompt: str) -> list[str]

The command that runs the agent unattended on prompt.

Raises:

Type Description
TaskError

When the kit declares no program to run the agent unattended.

prompt async

prompt(prompt: str, *, timeout: float | str | timedelta | None = None, working_dir: str | None = None, env: Mapping[str, str] | None = None) -> AgentRun

Runs the agent once on prompt, without a terminal, and waits for it.

Parameters:

Name Type Description Default
prompt str

The task for the agent.

required
timeout float | str | timedelta | None

Deadline of the wait for the run; none by default. It ends the wait, not the agent, which goes on until it ends or its sandbox is removed.

None
working_dir str | None

Working directory; the sandbox's by default.

None
env Mapping[str, str] | None

Additional environment variables, in clear in the sandbox.

None

Raises:

Type Description
SandboxTimeoutError

When the run does not end in time, its operation then agent run; or when its exit code does not come within 10 s of the end of its output, execution exit.

TaskError

When the kit declares no program to run the agent unattended.

stream async

stream(prompt: str, *, working_dir: str | None = None) -> AsyncIterator[Any]

Runs the agent once on prompt, yielding what it reports.

Parsed JSON lines for agents that report JSON lines, text lines otherwise. It has no deadline of its own: the timeout of the task bounds it, when the task has one. Leaving the loop early stops the reading, not the agent, which stops when its sandbox is removed.

Raises:

Type Description
TaskError

When the kit declares no program to run the agent unattended.

session async

session(*args: str, tty: bool = True, size: tuple[int, int] | None = None) -> Interactive

Starts an interactive session with the agent, as sbx run does.

fastsandbox.AgentRun

Bases: BaseModel

The outcome of one unattended agent run.

Attributes:

Name Type Description
exit_code int

Exit code of the agent.

stdout str

What it wrote on its standard output.

stderr str

What it wrote on its standard error.

events list[Any]

The JSON lines of stdout, for agents that report JSON lines.

ok property

ok: bool

Whether the agent exited with code 0.