Skip to content

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

BackendExtraIsolation
LocalSandboxBackend— (elsai-agents)None — host subprocess (dev only)
AgentCoreSandboxTemplateagent-core-code-interpreterAWS Bedrock AgentCore VM
DaytonaSandboxTemplatesandbox-daytonaRemote 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 LocalSandboxBackend

Host-mounted workspace. No process isolation — commands run as subprocesses on the same machine.

ParameterRequiredDefaultDescription
workspace_rootYes—Host directory used as the workspace root and default working directory.
timeoutNo120Default command timeout in seconds. Commands exceeding this return exit code 124.
max_output_bytesNo100000Maximum combined stdout/stderr bytes captured. Longer output includes an (output truncated) marker.
inherit_envNoTrueWhether subprocesses inherit the parent process environment.
envNoNoneAdditional 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 AgentCoreSandboxTemplate

Configuration template for session-scoped AgentCore Code Interpreter backends.

ParameterRequiredDefaultDescription
regionNoenv / account defaultAWS region for Bedrock AgentCore.
identifierNoNoneCode interpreter identifier override.
session_timeout_secondsNo900Remote 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.

ParameterRequiredDefaultDescription
session_nameYes—Session name bound to the workspace ID.
regionNoenv defaultAWS region.
identifierNoNoneCode interpreter identifier.
session_timeout_secondsNo900Remote session timeout.
auto_createNoTrueAutomatically initialize the AgentCore session on create().
persist_sessionsNoTrueReuse session mapping across calls.

Backend notes:

  • Wraps the same AgentCore Code Interpreter used by the legacy code_interpreter tool.
  • execute() does not honor a per-command timeout argument — use session_timeout_seconds on the template or wrap calls with asyncio.timeout().
  • seed_workspace reads files as UTF-8 text (errors="replace"). Binary assets may not round-trip correctly.

Environment variables (host process):

VariableRequiredDescription
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEYYes*Standard boto3 credentials
AWS_SESSION_TOKENNoSTS / assumed-role token
AWS_REGIONNoRegion fallback when region= is omitted
AWS_PROFILENoNamed 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 DaytonaSandboxTemplate

Configuration template for session-scoped Daytona sandboxes.

ParameterRequiredDefaultDescription
api_keyNoenv / Daytona defaultDaytona API key.
api_urlNoenv defaultDaytona API URL.
targetNoenv defaultDaytona target.
default_timeoutNo900Default command timeout in seconds. 0 waits until the command exits.
sync_polling_intervalNo0.1Seconds between polls while waiting for command completion.
imageNoNoneRegistry name such as "docker:dind", or a Daytona Image.
snapshotNoNoneName of an existing Daytona snapshot.
resourcesNoNoneDaytonaSandboxResources. Valid together with image.
env_varsNo()Sandbox shell variables. A dict or pairs is stored as a sorted tuple of string pairs.
labelsNo()Labels, stored the same way as env_vars.
auto_stop_intervalNoNoneMinutes until Daytona stops the sandbox. 0 disables auto-stop.
auto_delete_intervalNoNoneMinutes until Daytona deletes the sandbox.
ephemeralNoNonePassed through to the Daytona SDK when set.
create_timeoutNo60Seconds for sandbox create, and for start when attaching. 0 means no limit.
dockerNoNoneDaytonaDockerOptions. None leaves Docker handling off.
on_closeNo"stop""stop", "delete", or "detach".
sandbox_idNoNoneAttach 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):

VariableRequiredDescription
DAYTONA_API_KEYYes*Daytona API key
DAYTONA_API_URLNoAPI URL (default https://app.daytona.io/api)
DAYTONA_TARGETNoTarget runner (us, eu, …)
DAYTONA_JWT_TOKENAlt*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 DaytonaSandboxResources

CPU, 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.

ParameterRequiredDefaultDescription
cpuNoNonevCPUs.
memoryNoNoneMemory in GiB.
diskNoNoneDisk in GiB. Daytona enforces the organization cap and rejects a larger request.

DaytonaDockerOptions ​

python
from elsai_tools.sandbox import DaytonaDockerOptions

How the backend makes Docker usable after the sandbox exists. Pass DaytonaDockerOptions() to turn the ready-check on.

ParameterRequiredDefaultDescription
start_daemonNoTrueStart dockerd when docker info fails. False only waits, for an image whose entrypoint already runs the daemon.
dockerd_pathNo/usr/local/bin/dockerdAbsolute path to the daemon.
log_pathNo/tmp/dockerd.logDaemon output. The tail is included in the error if Docker never becomes ready.
ready_timeoutNo60Seconds to wait for docker info. Must be greater than 0.
poll_intervalNo2Seconds between docker info retries. Must be greater than 0.

DaytonaDockerNotReadyError ​

python
from elsai_tools.sandbox import DaytonaDockerNotReadyError

Raised 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.

AttributeDescription
sandbox_idId of the sandbox that did not become ready.
log_tailLast 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 ​

ParameterRequiredDefaultDescription
session_nameYes—Session name for logging and identification.
api_keyNoenv defaultDaytona API key.
api_urlNoenv defaultDaytona API URL.
targetNoenv defaultDaytona target.
default_timeoutNo900Default command timeout. 0 means poll until the command completes (no wall-clock limit).
sync_polling_intervalNo0.1Poll interval for command completion.
sandboxNoNonePre-created Daytona sandbox instance (testing).
daytona_clientNoNonePre-created Daytona client (testing).

Backend notes:

  • Extends BaseSandbox in elsai.execution — uses native Daytona filesystem APIs where possible.
  • build_for_session copies image, snapshot, resources, env_vars, labels, auto_stop_interval, auto_delete_interval, ephemeral, create_timeout, docker, on_close, and sandbox_id from 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(). For docker:dind that root is /workspace, and execute() with no cwd runs there.
  • When docker is set, create() returns after docker info succeeds. A ready-check that times out raises DaytonaDockerNotReadyError.

vs code_interpreter tool ​

Sandbox + backendcode_interpreter prebuilt tool
PurposeFull project workspace (shell + files)Code-interpreter action API
Agent toolsexecute, read_file, write_file, list_dircode_interpreter with action payloads
Multi-agent sharingSame Sandbox instancePer-context via A2A
Recommended forNew sandbox execution workflowsLegacy or code-only AgentCore sessions

See Code interpretation.


Copyright © 2026 elsai foundry.