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.3.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).

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.