automaton.sandbox¶
WARNING
This documentation is almost entirely "vibe coded"; while a helpful resource for humans and agents to understand this codebase, it should not be considered a source of ground truth in the way documentation normally is, and the user is responsible for verifying that all instructions given here are safe.
automaton.sandbox
¶
Sandboxed execution engine for Automaton.
:class:Sandbox runs commands inside a Charliecloud container with a clean,
minimal environment and optional memory limits. It provides two entry points:
- :meth:
Sandbox.run_command-- run an arbitrary, non-agentic command inside a container. By default this runs with loopback-only networking and no model proxy. This is the general-purpose "run some code against the deliverable" path (a benchmark orchestrator uses it for environment setup and verification). - :meth:
Sandbox.run_agent-- run an autonomous agent (a harness driving one or more models) inside the container, brokering all model traffic through a loopback-only :class:~automaton.proxy.ModelProxy. The agent's deliverable is left in the bind-mounted workspace directory. Returns an :class:ExecutionResult; Automaton stays agnostic about the deliverable's contents.
Automaton is content-free: the caller supplies the container image, the harness, the agent, staged file paths, and bind mounts.
MemoryCgroupUnavailable
¶
Bases: RuntimeError
memory_cgroup was requested but a memory-capped scope cannot be created.
BindMount
dataclass
¶
Host/container bind mount specification for Charliecloud.
CommandRunFailed
¶
Bases: RuntimeError
A sandboxed command exited non-zero.
Attributes:
| Name | Type | Description |
|---|---|---|
returncode |
int
|
Process return code. |
log_file |
Path
|
Path to the command's log file. |
detail |
str
|
Human-readable failure detail. |
Source code in automaton/sandbox.py
ExecutionResult
dataclass
¶
ExecutionResult(success: bool, workspace: Path, returncode: int | None = None, endpoint_exhausted: bool = False, context_length_exceeded: bool = False, failure_detail: str | None = None, proxy_error_detail: str | None = None, usage_records: list[dict[str, Any]] = list(), usage_summary: dict[str, Any] = dict(), log_file: Path | None = None, blocked_provider_executed_tools: list[str] = list(), dry_run: bool = False, budget_exhausted: bool = False, interrupted: bool = False, oom_kills: int = 0, memory_limit_bytes: int | None = None)
Result of running an agent in the sandbox.
Automaton is agnostic about the deliverable's contents; it reports only execution facts and the workspace location where the deliverable lives.
Attributes:
| Name | Type | Description |
|---|---|---|
success |
bool
|
Whether the harness process exited cleanly. |
returncode |
int | None
|
Harness process return code (None if not run, e.g. dry-run). |
workspace |
Path
|
Host path to the deliverable workspace. |
endpoint_exhausted |
bool
|
True if the model proxy could not obtain a complete upstream response. |
context_length_exceeded |
bool
|
True if the harness failed because an upstream request exceeded the model's context window (an oversized-prompt HTTP 4xx). |
failure_detail |
str | None
|
Failure detail when |
proxy_error_detail |
str | None
|
Last upstream/model proxy error, if any. |
usage_records |
list[dict]
|
Per-request usage/cost accounting records from the model proxy. |
usage_summary |
dict
|
Aggregated usage summary computed from |
log_file |
Path | None
|
Path to the harness process log. |
blocked_provider_executed_tools |
list[str]
|
Provider-executed tool types the model proxy refused to forward. Non-empty means the agent tried to use a tool that runs on the provider's infrastructure outside the sandbox; the run should not be graded as an ordinary task failure. |
dry_run |
bool
|
True if this was a dry run (no execution performed). |
Sandbox
¶
Sandbox(host_root: Path | None = None, dry_run: bool = False, stream_output: bool = True, harness_memory_limit_bytes: int | None = None, harness_memory_limit_fraction: float | None = 0.9, proxy_api_key_env: str = DEFAULT_PROXY_API_KEY_ENV, proxy_api_key_value: str = DEFAULT_PROXY_API_KEY_VALUE, proxy_provider_id: str = DEFAULT_PROXY_PROVIDER_ID, sandbox_proxy_port: int = DEFAULT_SANDBOX_PROXY_PORT, container_run_root: Path = DEFAULT_CONTAINER_RUN_ROOT, container_workspace_root: Path = DEFAULT_CONTAINER_WORKSPACE_ROOT, container_base_root: Path = Path('/automaton/base'), allowed_provider_executed_tools: frozenset[str] | set[str] | None = None, memory_cgroup: bool = False)
Runs commands and agents inside a Charliecloud container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host_root
|
Path
|
Host directory bound into the container as |
None
|
dry_run
|
bool
|
If True, print commands instead of executing them. |
False
|
stream_output
|
bool
|
If True, mirror container output to the terminal. |
True
|
harness_memory_limit_bytes
|
int
|
Fixed harness memory cap in bytes. |
None
|
harness_memory_limit_fraction
|
float
|
Fraction of available memory to cap the harness at. Default 0.9. |
0.9
|
proxy_api_key_env
|
str
|
Env var name the harness reads for the proxy auth token. |
DEFAULT_PROXY_API_KEY_ENV
|
proxy_api_key_value
|
str
|
Proxy auth token value. |
DEFAULT_PROXY_API_KEY_VALUE
|
proxy_provider_id
|
str
|
Provider id used for proxied model routing ( |
DEFAULT_PROXY_PROVIDER_ID
|
sandbox_proxy_port
|
int
|
Loopback port the sandbox-local proxy listens on. |
DEFAULT_SANDBOX_PROXY_PORT
|
container_run_root
|
Path
|
In-container root for staged run assets. |
DEFAULT_CONTAINER_RUN_ROOT
|
container_workspace_root
|
Path
|
In-container workspace mount point. |
DEFAULT_CONTAINER_WORKSPACE_ROOT
|
container_base_root
|
Path
|
Default in-container mount point for |
Path('/automaton/base')
|
allowed_provider_executed_tools
|
Iterable[str]
|
Provider-executed tool types the model proxy may forward. Defaults to none, which blocks them: such tools run on the provider's infrastructure instead of in the sandbox, so the sandbox network namespace cannot confine them and their use leaves no trace in the harness transcript. |
None
|
memory_cgroup
|
bool
|
If True, enforce memory caps with a cgroup instead of |
False
|
Source code in automaton/sandbox.py
sandbox_helper_script
¶
harness_models_config
¶
harness_models_config(agent: Agent, *, sandboxed: bool = True) -> dict[str, Any]
Build the harness-facing models config (proxy wiring).
When sandboxed is True, models are routed through the loopback
proxy; otherwise the harness talks to the upstream base_url directly.
Source code in automaton/sandbox.py
model_registry
¶
model_registry(agent: Agent) -> dict[str, dict[str, Any]]
Build the upstream model registry consumed by :class:ModelProxy.
Source code in automaton/sandbox.py
run_command
¶
run_command(container_path: Path, argv: list[str], *, cwd: Path | None = None, env_vars: dict[str, str] | None = None, bind_mounts: list[BindMount] | None = None, log_file: Path | None = None, memory_limit_bytes: int | None = None, network: bool = False, check: bool = True) -> int
Run an arbitrary command inside the container.
By default runs with loopback-only networking (network=False) and
no model proxy. This is the general-purpose path for running
non-agentic code (setup, verification, tooling) against a workspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_path
|
Path
|
Path to the built container directory. |
required |
argv
|
list[str]
|
Command to run inside the container (e.g. |
required |
cwd
|
Path
|
Working directory inside the container. |
None
|
env_vars
|
dict[str, str]
|
Extra environment variables to set inside the container. |
None
|
bind_mounts
|
list[BindMount]
|
Bind mounts. Defaults to binding |
None
|
log_file
|
Path
|
Combined stdout/stderr log path. |
None
|
memory_limit_bytes
|
int
|
Memory cap for the command. |
None
|
network
|
bool
|
If False (default), run inside a loopback-only network namespace with no outbound access. If True, run without network isolation. |
False
|
check
|
bool
|
If True, raise :class: |
True
|
Returns:
| Type | Description |
|---|---|
int
|
The command's return code (or 0 in dry-run mode). |
Source code in automaton/sandbox.py
run_agent
¶
run_agent(container_path: Path, harness: Harness, agent: Agent, *, workspace: Path, run_dir: Path, container_paths: dict[str, Path], bind_mounts: list[BindMount], proxy_log: Path, usage_records_file: Path, harness_output_dir: Path, models_config_file: Path, harness_config_file: Path, extra_env: dict[str, str] | None = None, timeout: int | None = None, sandboxed: bool = True, budget_exhausted_callback: 'Callable[[str], None] | None' = None, stop_check: 'Callable[[], bool] | None' = None) -> ExecutionResult
Run an autonomous agent inside the sandbox.
stop_check (opt-in) is polled while the agent runs; once it returns
True the agent's whole process tree is terminated and the result is
reported as unsuccessful with interrupted=True. With the default
None behaviour is unchanged.
The caller is responsible for staging the workspace, prompt, harness
assets, and sandbox helper script into run_dir before calling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_path
|
Path
|
Built runtime container directory. |
required |
harness
|
Harness
|
Loaded harness. |
required |
agent
|
Agent
|
Configured agent (harness + models). |
required |
workspace
|
Path
|
In-container workspace path (where the deliverable is produced). |
required |
run_dir
|
Path
|
Host per-run directory (already populated with staged assets). |
required |
container_paths
|
dict[str, Path]
|
In-container paths for staged assets. Required keys:
|
required |
bind_mounts
|
list[BindMount]
|
Bind mounts for the run. |
required |
proxy_log
|
Path
|
Model proxy log path. |
required |
usage_records_file
|
Path
|
JSONL path for per-request usage records. |
required |
harness_output_dir
|
Path
|
Host directory for harness output/logs. |
required |
models_config_file
|
Path
|
Host path to write the harness models config to. |
required |
harness_config_file
|
Path
|
Host path to write the agent harness config to. |
required |
extra_env
|
dict[str, str]
|
Additional environment variables passed into the harness container (e.g. task-facing workspace/env variables the caller defines). |
None
|
timeout
|
int
|
Per-run timeout in seconds passed to the harness. |
None
|
sandboxed
|
bool
|
If True (default), route model traffic through the loopback proxy and run the harness in an isolated network namespace. If False, run the harness with direct network access to upstream models. |
True
|
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
Execution facts and deliverable workspace location. |
Source code in automaton/sandbox.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
memory_limit_bytes
¶
The memory cap this sandbox applies to the harness, in bytes, if any.
Callers can pass it to :meth:run_command to cap setup and
verification commands the same way.