Appearance
Sandbox Backends
Remote and local execution backends for Sandbox and per-agent AgentConfig.execution_backend.
Package: elsai-agents-tools (AgentCore, Daytona) and elsai-agents (Local)
Import namespace: elsai_tools.sandbox, elsai.execution
These implement the SandboxBackend protocol — they are not agent tools. Pass a template or instance to Sandbox(backend=...).
← Prebuilt Tools overview · Sandbox concept
| Backend | Extra | Isolation |
|---|---|---|
LocalSandboxBackend | — (elsai-agents) | None — host subprocess (dev only) |
AgentCoreSandboxTemplate | agent-core-code-interpreter | AWS Bedrock AgentCore VM |
DaytonaSandboxTemplate | sandbox-daytona | Remote Daytona workspace |
Installation
bash
# AWS Bedrock AgentCore
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ \
"elsai-agents-tools[agent-core-code-interpreter]==0.3.0"
# Daytona
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ \
"elsai-agents-tools[sandbox-daytona]==0.4.0"The sandbox-daytona extra requires daytona-sdk>=0.231.1,<1.0.0.
Requires elsai-agents>=0.3.3 for the sandbox execution model.
Import
python
from elsai.execution import LocalSandboxBackend
from elsai_tools.sandbox import (
AgentCoreSandboxTemplate,
DaytonaDockerNotReadyError,
DaytonaDockerOptions,
DaytonaSandboxResources,
DaytonaSandboxTemplate,
)If an optional dependency is missing, the corresponding class is set to None at import time (the elsai_tools.sandbox package does not fail). Import from elsai_tools.sandbox — not from elsai_tools.code_interpreter.
Wiring with Sandbox
Templates expose build_for_session(session_id); SandboxManager materializes the live backend per workspace_id.
python
from elsai import Agent
from elsai.agent import AgentConfig
from elsai.execution import Sandbox, workspace_id_for_run
from elsai.plugins.sandbox import SandboxPlugin
from elsai_tools.sandbox import AgentCoreSandboxTemplate
async with Sandbox(
workspace_id=workspace_id_for_run("my-run"),
backend=AgentCoreSandboxTemplate(region="us-west-2"),
ttl_seconds=7200,
seed_from="/path/to/project",
) as sandbox:
agent = Agent(
config=AgentConfig(
sandbox=sandbox,
plugins=[SandboxPlugin()],
),
)
await agent.invoke_async("Run tests and summarize results")LocalSandboxBackend
python
from elsai.execution import LocalSandboxBackendHost-mounted workspace. No process isolation — commands run as subprocesses on the same machine.
| Parameter | Required | Default | Description |
|---|---|---|---|
workspace_root | Yes | — | Host directory used as the workspace root and default working directory. |
timeout | No | 120 | Default command timeout in seconds. Commands exceeding this return exit code 124. |
max_output_bytes | No | 100000 | Maximum combined stdout/stderr bytes captured. Longer output includes an (output truncated) marker. |
inherit_env | No | True | Whether subprocesses inherit the parent process environment. |
env | No | None | Additional environment variables (merged when inherit_env=True). |
Environment: No Elsai-specific variables. With inherit_env=True (default), workspace subprocesses receive the host process environment. For local_dev + host prebuilt tools in CI, set BYPASS_TOOL_CONSENT=true — see Tool consent.
Development only
A warning is logged at initialization. Use AgentCore or Daytona for production workloads.
AgentCoreSandboxTemplate
python
from elsai_tools.sandbox import AgentCoreSandboxTemplateConfiguration template for session-scoped AgentCore Code Interpreter backends.
| Parameter | Required | Default | Description |
|---|---|---|---|
region | No | env / account default | AWS region for Bedrock AgentCore. |
identifier | No | None | Code interpreter identifier override. |
session_timeout_seconds | No | 900 | Remote session lifetime in seconds. |
build_for_session(session_id)
Returns an AgentCoreSandboxBackend bound to session_id (typically the sandbox workspace_id).
AgentCoreSandboxBackend
Usually created via the template — not constructed directly in application code.
| Parameter | Required | Default | Description |
|---|---|---|---|
session_name | Yes | — | Session name bound to the workspace ID. |
region | No | env default | AWS region. |
identifier | No | None | Code interpreter identifier. |
session_timeout_seconds | No | 900 | Remote session timeout. |
auto_create | No | True | Automatically initialize the AgentCore session on create(). |
persist_sessions | No | True | Reuse session mapping across calls. |
Backend notes:
- Wraps the same AgentCore Code Interpreter used by the legacy
code_interpretertool. execute()does not honor a per-commandtimeoutargument — usesession_timeout_secondson the template or wrap calls withasyncio.timeout().seed_workspacereads files as UTF-8 text (errors="replace"). Binary assets may not round-trip correctly.
Environment variables (host process):
| Variable | Required | Description |
|---|---|---|
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY | Yes* | Standard boto3 credentials |
AWS_SESSION_TOKEN | No | STS / assumed-role token |
AWS_REGION | No | Region fallback when region= is omitted |
AWS_PROFILE | No | Named boto3 profile |
*Not required with an instance/task IAM role, or when equivalent values are resolved by boto3 another way.
Class method AgentCoreSandboxBackend.template(...)
Convenience for building an AgentCoreSandboxTemplate with the same parameters.
DaytonaSandboxTemplate
python
from elsai_tools.sandbox import DaytonaSandboxTemplateConfiguration template for session-scoped Daytona sandboxes.
| Parameter | Required | Default | Description |
|---|---|---|---|
api_key | No | env / Daytona default | Daytona API key. |
api_url | No | env default | Daytona API URL. |
target | No | env default | Daytona target. |
default_timeout | No | 900 | Default command timeout in seconds. 0 waits until the command exits. |
sync_polling_interval | No | 0.1 | Seconds between polls while waiting for command completion. |
image | No | None | Registry name such as "docker:dind", or a Daytona Image. |
snapshot | No | None | Name of an existing Daytona snapshot. |
resources | No | None | DaytonaSandboxResources. Valid together with image. |
env_vars | No | () | Sandbox shell variables. A dict or pairs is stored as a sorted tuple of string pairs. |
labels | No | () | Labels, stored the same way as env_vars. |
auto_stop_interval | No | None | Minutes until Daytona stops the sandbox. 0 disables auto-stop. |
auto_delete_interval | No | None | Minutes until Daytona deletes the sandbox. |
ephemeral | No | None | Passed through to the Daytona SDK when set. |
create_timeout | No | 60 | Seconds for sandbox create, and for start when attaching. 0 means no limit. |
docker | No | None | DaytonaDockerOptions. None leaves Docker handling off. |
on_close | No | "stop" | "stop", "delete", or "detach". |
sandbox_id | No | None | Attach to a sandbox that already exists. Blank or whitespace is stored as None. |
A template that sets only api_key, api_url, and target keeps the 0.3.0 behavior. When api_key, api_url, and target are all omitted, the Daytona SDK default client is used (typically environment-based configuration).
image and snapshot cannot both be set. resources requires image, because a snapshot's size is fixed when the snapshot is created. sandbox_id together with on_close="delete" raises ValueError. create_timeout and default_timeout must be >= 0.
Attach uses docker and on_close. It leaves the existing image, resources, env vars, labels, and lifecycle intervals as they are. Setting docker does not require image. A snapshot can already contain Docker.
Environment variables (host process):
| Variable | Required | Description |
|---|---|---|
DAYTONA_API_KEY | Yes* | Daytona API key |
DAYTONA_API_URL | No | API URL (default https://app.daytona.io/api) |
DAYTONA_TARGET | No | Target runner (us, eu, …) |
DAYTONA_JWT_TOKEN | Alt* | JWT authentication instead of API key |
*Read from the environment when omitted on the template — see Daytona configuration.
DaytonaSandboxResources
python
from elsai_tools.sandbox import DaytonaSandboxResourcesCPU, memory, and disk for a sandbox created from an image. Memory and disk are GiB. None lets Daytona choose. A set value must be a positive int.
| Parameter | Required | Default | Description |
|---|---|---|---|
cpu | No | None | vCPUs. |
memory | No | None | Memory in GiB. |
disk | No | None | Disk in GiB. Daytona enforces the organization cap and rejects a larger request. |
DaytonaDockerOptions
python
from elsai_tools.sandbox import DaytonaDockerOptionsHow the backend makes Docker usable after the sandbox exists. Pass DaytonaDockerOptions() to turn the ready-check on.
| Parameter | Required | Default | Description |
|---|---|---|---|
start_daemon | No | True | Start dockerd when docker info fails. False only waits, for an image whose entrypoint already runs the daemon. |
dockerd_path | No | /usr/local/bin/dockerd | Absolute path to the daemon. |
log_path | No | /tmp/dockerd.log | Daemon output. The tail is included in the error if Docker never becomes ready. |
ready_timeout | No | 60 | Seconds to wait for docker info. Must be greater than 0. |
poll_interval | No | 2 | Seconds between docker info retries. Must be greater than 0. |
DaytonaDockerNotReadyError
python
from elsai_tools.sandbox import DaytonaDockerNotReadyErrorRaised when Docker does not become ready. It is a RuntimeError. The message includes the sandbox id, how long the wait ran, and the last daemon log lines.
| Attribute | Description |
|---|---|
sandbox_id | Id of the sandbox that did not become ready. |
log_tail | Last lines of the daemon log. Empty when the log could not be read. |
build_for_session(session_id)
Returns a DaytonaSandboxBackend bound to session_id.
DaytonaSandboxBackend
| Parameter | Required | Default | Description |
|---|---|---|---|
session_name | Yes | — | Session name for logging and identification. |
api_key | No | env default | Daytona API key. |
api_url | No | env default | Daytona API URL. |
target | No | env default | Daytona target. |
default_timeout | No | 900 | Default command timeout. 0 means poll until the command completes (no wall-clock limit). |
sync_polling_interval | No | 0.1 | Poll interval for command completion. |
sandbox | No | None | Pre-created Daytona sandbox instance (testing). |
daytona_client | No | None | Pre-created Daytona client (testing). |
Backend notes:
- Extends
BaseSandboxinelsai.execution— uses native Daytona filesystem APIs where possible. build_for_sessioncopiesimage,snapshot,resources,env_vars,labels,auto_stop_interval,auto_delete_interval,ephemeral,create_timeout,docker,on_close, andsandbox_idfrom the template.execute()creates an ephemeral process session per command, then polls until exit or timeout.- Workspace paths are mapped to the sandbox work directory from
sandbox.get_work_dir(). Fordocker:dindthat root is/workspace, andexecute()with nocwdruns there. - When
dockeris set,create()returns afterdocker infosucceeds. A ready-check that times out raisesDaytonaDockerNotReadyError.
vs code_interpreter tool
| Sandbox + backend | code_interpreter prebuilt tool | |
|---|---|---|
| Purpose | Full project workspace (shell + files) | Code-interpreter action API |
| Agent tools | execute, read_file, write_file, list_dir | code_interpreter with action payloads |
| Multi-agent sharing | Same Sandbox instance | Per-context via A2A |
| Recommended for | New sandbox execution workflows | Legacy or code-only AgentCore sessions |
See Code interpretation.