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.3.0"

Requires elsai-agents>=0.3.0 for the sandbox execution model.


Import

python
from elsai.execution import LocalSandboxBackend
from elsai_tools.sandbox import AgentCoreSandboxTemplate, 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_rootYesHost 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_nameYesSession 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.
sync_polling_intervalNo0.1Seconds between polls while waiting for command completion.

When api_key, api_url, and target are all omitted, the Daytona SDK default client is used (typically environment-based configuration).

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.

build_for_session(session_id)

Returns a DaytonaSandboxBackend bound to session_id.

DaytonaSandboxBackend

ParameterRequiredDefaultDescription
session_nameYesSession 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.
  • 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().

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.