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.
SHELL
class-attribute
instance-attribute
¶
A plain shell: no agent, the base of other kits.
keys
property
¶
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
¶
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
¶
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
¶
fastsandbox.Headless
dataclass
¶
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 ( |
fastsandbox.AgentRunner
¶
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. |
|
kit_agent |
The agent its kit declares: its program and the options of its sessions. |
command
¶
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 |
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. |
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 |