Skip to content

Sandbox — Backends ​

An execution backend is where sandbox commands and file operations actually run. Pass a backend instance or template to Sandbox(backend=...).

BackendPackageIsolationBest for
LocalSandboxBackendelsai-agentsNone (host)Local dev and tests
AgentCoreSandboxTemplateelsai-agents-toolsAWS AgentCore VMProduction on Bedrock
DaytonaSandboxTemplateelsai-agents-toolsRemote Daytona workspaceRemote dev environments

Full parameter reference: Sandbox backends API.

Local development ​

python
from pathlib import Path

from elsai.execution import LocalSandboxBackend, Sandbox, workspace_id_for_run

async with Sandbox(
    workspace_id=workspace_id_for_run("local-dev"),
    backend=LocalSandboxBackend(Path("/tmp/elsai-sandbox")),
    ttl_seconds=3600,
    seed_from=Path("./my-repo"),
) as sandbox:
    ...

What this shows:

PieceConcept
LocalSandboxBackendUses a host directory — subprocesses run on your machine
No extra installShips with elsai-agents

Not isolated

Logs a warning at init. Do not use for production agent workloads with untrusted input.

Pair with SandboxMode.LOCAL_DEV on the per-agent advanced path if you also need host prebuilt tools alongside sandbox tools. Shared Sandbox attach uses production host-tool blocking — AgentConfig(sandbox=..., sandbox_mode=local_dev) raises ValueError at construction.

Environment: Subprocesses inherit the host process environment when inherit_env=True (default). Pass extra variables with env= on the constructor — see LocalSandboxBackend. For local_dev workflows that also use host prebuilt tools, set BYPASS_TOOL_CONSENT=true in CI — see Tool consent.

Secrets

Default seed excludes .env, *.pem, credentials.json, and secrets/ — see DEFAULT_SANDBOX_SEED_EXCLUDES. With LocalSandboxBackend, subprocesses can still see the host environment when inherit_env=True.

AWS Bedrock AgentCore ​

bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ \
  "elsai-agents-tools[agent-core-code-interpreter]==0.3.0"
python
from elsai_tools.sandbox import AgentCoreSandboxTemplate

async with Sandbox(
    workspace_id=workspace_id_for_run(run_id),
    backend=AgentCoreSandboxTemplate(
        region="us-west-2",
        session_timeout_seconds=900,
    ),
    ttl_seconds=7200,
    seed_from="/path/to/repo",
) as sandbox:
    ...

What this shows:

PieceConcept
AgentCoreSandboxTemplateConfig object; manager calls build_for_session(workspace_id)
AWS credentials on hostAgent never runs inside the VM with your API keys

Operational notes:

  • Per-command timeout on execute is not honored — configure session_timeout_seconds or use asyncio.timeout() at the call site
  • Project seeding reads files as UTF-8 text

Requires IAM permissions for Bedrock AgentCore Code Interpreter in your AWS account.

Environment variables (host process — or use an IAM role on EC2, ECS, Lambda, …):

VariableRequiredNotes
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEYYes*Standard boto3 credentials
AWS_SESSION_TOKENNoTemporary / assumed-role credentials
AWS_REGIONNoUsed when region= is omitted on the template
AWS_PROFILENoNamed AWS profile

*Not required when credentials come from an instance/task role, or when you pass region= explicitly and boto3 resolves credentials another way.

Daytona ​

bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ \
  "elsai-agents-tools[sandbox-daytona]==0.4.0"
python
from elsai_tools.sandbox import DaytonaSandboxTemplate

async with Sandbox(
    workspace_id=workspace_id_for_run(run_id),
    backend=DaytonaSandboxTemplate(
        api_key="...",  # or omit to use Daytona SDK env defaults
        default_timeout=900,
    ),
    ttl_seconds=7200,
    seed_from="/path/to/repo",
) as sandbox:
    ...

What this shows:

PieceConcept
DaytonaSandboxTemplateCreates remote Daytona workspace per session
Native FS APIsFile ops use Daytona filesystem; commands use ephemeral process sessions

Operational notes:

  • Each execute call creates a short-lived process session and polls until completion
  • default_timeout=0 waits until the command finishes with no wall-clock limit

Environment variables (host process — or pass api_key=, api_url=, target= on the template):

VariableRequiredNotes
DAYTONA_API_KEYYes*API key from the Daytona dashboard
DAYTONA_API_URLNoDefaults to https://app.daytona.io/api
DAYTONA_TARGETNoRunner region (us, eu, …)
DAYTONA_JWT_TOKENAlt*JWT from daytona login instead of API key

*When all constructor args are omitted, the Daytona SDK reads these from the environment (and optional .env).

Docker inside the sandbox ​

elsai-agents-tools 0.4.0 can run a Docker engine inside the Daytona workspace. Agent, Sandbox, and the execute tool stay the same. A template that sets only api_key, api_url, and target keeps the 0.3.0 behavior.

python
from elsai_tools.sandbox import (
    DaytonaDockerOptions,
    DaytonaSandboxResources,
    DaytonaSandboxTemplate,
)

async with Sandbox(
    workspace_id=workspace_id_for_run(run_id),
    backend=DaytonaSandboxTemplate(
        image="docker:dind",
        resources=DaytonaSandboxResources(cpu=2, memory=4, disk=10),
        auto_stop_interval=30,
        create_timeout=0,
        default_timeout=1800,
        docker=DaytonaDockerOptions(),
        on_close="delete",
    ),
    ttl_seconds=7200,
) as sandbox:
    ...

What this shows:

PieceConcept
image="docker:dind"Daytona builds the sandbox from that image
resourcesCPU, memory, and disk in GiB for an image create
docker=DaytonaDockerOptions()Starts the daemon and waits until docker info succeeds. Sandbox start returns after that
on_close="delete"Deletes the sandbox when the workspace closes
create_timeout=0Waits until the image build finishes. The first build can take several minutes
default_timeout=1800Per-command limit. A first docker build that pulls a large base image can run past the default 900 seconds

The agent builds and runs containers with execute, the same workspace tool as any other Daytona sandbox.

To come back to a sandbox that already exists, pass its id and leave it in place when the workspace closes:

python
async with Sandbox(
    workspace_id=workspace_id_for_run(run_id),
    backend=DaytonaSandboxTemplate(
        sandbox_id="your-sandbox-id",
        create_timeout=0,
        default_timeout=1800,
        docker=DaytonaDockerOptions(),
        on_close="stop",
    ),
    ttl_seconds=7200,
) as sandbox:
    ...

Operational notes:

  • Project files for docker:dind land in /workspace. A command with no cwd runs there, so docker build . sees the files write_file wrote.
  • on_close is "stop" (default; keeps the disk, including image layers), "delete", or "detach" (drops the local handle and leaves the sandbox running until its own auto-stop).
  • sandbox_id attaches to an existing sandbox. Pair it with "stop" or "detach". Attach keeps the image, disk, and auto-stop already on that sandbox. docker still applies: after a stop, the backend starts dockerd again, and image layers stay on disk.
  • docker:dind is Alpine and includes sh. Add bash, python, pip, git, or curl in the image when the agent needs them.
  • env_vars are the sandbox shell's variables. Pass -e or --env-file on docker run to give a container those values.
  • Disk is the limit that shows up inside the sandbox. On a typical account the cap is 10 GB. CPU and memory reported by docker info are the host the daemon can see. The create still uses the resources you set.
  • Set DAYTONA_API_KEY in the environment, or pass api_key= on the template.

Field reference: DaytonaSandboxTemplate, DaytonaSandboxResources, DaytonaDockerOptions.

Production flow — shared workspace ​

python
import asyncio
from elsai import Agent
from elsai.agent import AgentConfig, SandboxAttachMode
from elsai.execution import Sandbox, workspace_id_for_run
from elsai.plugins.sandbox import SandboxPlugin
from elsai_tools.sandbox import AgentCoreSandboxTemplate

async def main() -> None:
    run_id = "feature-auth"
    async with Sandbox(
        workspace_id=workspace_id_for_run(run_id),
        backend=AgentCoreSandboxTemplate(region="us-west-2"),
        ttl_seconds=7200,
        seed_from="/host/monorepo",
    ) as sandbox:
        coder = Agent(
            config=AgentConfig(sandbox=sandbox, plugins=[SandboxPlugin()]),
        )
        reviewer = Agent(
            config=AgentConfig(
                sandbox=sandbox,
                sandbox_attach_mode=SandboxAttachMode.READ_ONLY,
                plugins=[SandboxPlugin()],
            ),
        )

        await coder.invoke_async("Implement JWT refresh in services/auth/")
        await reviewer.invoke_async("Review services/auth/ for security issues")

asyncio.run(main())

What this shows:

PieceConcept
Remote backend + shared SandboxProduction isolation with multi-agent file sharing
Read-only reviewerAudit without write or execute access

Detach behavior is identical across backends — see Shared workspace — Attach and detach.

vs code_interpreter tool ​

Sandbox + backendcode_interpreter prebuilt tool
ScopeFull project workspaceCode-interpreter session actions
Toolsexecute, file ops via plugincode_interpreter payload API
Multi-agentShared SandboxPer A2A context
RecommendedNew workspace workflowsLegacy code-only sessions

See Code interpretation.

Optional import fallbacks ​

If bedrock_agentcore or daytona is not installed, the corresponding class in elsai_tools.sandbox is None. Install the matching extra before wiring production backends.

Copyright © 2026 elsai foundry.