Skip to content

Sandbox ​

A sandbox gives the agent a workspace. Shell and file tools run there, through SandboxPlugin. The model and API keys stay on the host. Runtime behavior, including which host tools are blocked, is on Sandbox.

Pick one configuration. They cannot be combined.

PathAgent keysWhen to use
Directsandbox_mode and execution_backendOne agent, one workspace
Sharedsandbox and optional sandbox_attach_modeSeveral agents on one filesystem

Both require plugins: to include type: SandboxPlugin.

The plugin registers execute, read_file, write_file, and list_dir. A read_only agent receives read_file and list_dir.


Installation ​

bash
pip install --upgrade --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents==0.4.4"
pip install --upgrade --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-yaml==0.4.3"

LocalSandboxBackend ships with elsai-agents. AgentCore and Daytona are extras on elsai-agents-tools. Each backend has its own example below.

A shared sandbox is built while the file loads and started on the first run. That start needs elsai-agents 0.4.2.


Local workspace ​

sandbox_mode: local_dev runs the workspace on the host directory. It requires type: LocalSandboxBackend.

agents.yaml:

yaml
openai:
  type: OpenAIModel
  model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"

workspace:
  type: LocalSandboxBackend
  workspace_root: ./workspace

analyst:
  type: Agent
  name: sandbox_analyst
  system_prompt: Use workspace tools for files and commands.
  model: ${openai}
  sandbox_mode: local_dev
  execution_backend: ${workspace}
  sandbox_output_offload:
    storage:
      type: InMemoryStorage
    max_result_tokens: 2500
    preview_tokens: 100
  plugins:
    - type: SandboxPlugin
python
from elsai.config import yaml_to_agent

agent = yaml_to_agent("agents.yaml", entry="analyst")
print(agent("Write note.txt, read it back, and list the folder."))

workspace_root is relative to the YAML file. sandbox_mode: sandbox is the other direct mode. It blocks host shell and file tools. local_dev is only valid with LocalSandboxBackend.

KeyMeaning
sandbox_modesandbox or local_dev
execution_backendA backend map or ${block}
workspace_rootHost directory seeded into the workspace. For a local backend, defaults to that backend’s workspace_root
workspace_sync_policyexclude_patterns and sync_include_patterns, each a list of strings
sandbox_manager{ttl_seconds: <positive number>}

Output offload ​

sandbox_output_offload stores a large tool result and leaves a short preview in the conversation. It needs a direct or shared sandbox.

KeyDefaultMeaning
storagerequiredInMemoryStorage, FileStorage, or S3Storage
max_result_tokens2500Offload results above this size
preview_tokens1000Preview left in context. Lower than max_result_tokens
include_retrieval_toolWhether a retrieval tool is added
tool_namesWhich sandbox tools to offload: execute, read_file, write_file, list_dir

FileStorage takes artifact_dir (default artifacts). S3Storage takes bucket, and optional prefix and region_name. Use {{$BUCKET:}} for the bucket name.


Shared workspace ​

One type: Sandbox block is one workspace for the agents built in that same load. Each agent still has its own conversation. See Shared workspace.

Build them together with yaml_to_graph. A second yaml_to_agent call starts a new load and a new sandbox, even when the block name matches.

yaml
openai:
  type: OpenAIModel
  model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"

workspace:
  type: Sandbox
  workspace_id: example-run
  ttl_seconds: 7200
  seed_from: ./project
  backend:
    type: LocalSandboxBackend
    workspace_root: ./sandbox

writer:
  type: Agent
  name: writer
  system_prompt: Write the change into the shared workspace.
  model: ${openai}
  sandbox: ${workspace}
  sandbox_attach_mode: read_write
  plugins:
    - type: SandboxPlugin

reviewer:
  type: Agent
  name: reviewer
  system_prompt: Read the workspace and comment. Do not change files.
  model: ${openai}
  sandbox: ${workspace}
  sandbox_attach_mode: read_only
  plugins:
    - type: SandboxPlugin

team:
  type: Graph
  nodes:
    write: ${writer}
    review: ${reviewer}
  edges:
    - from: write
      to: review
python
from elsai.config import yaml_to_graph

graph = yaml_to_graph("agents.yaml", entry="team")
print(graph("Add a note to TASK.md, then summarize that file."))

The sandbox is not started while the file loads. The first invocation starts it once, then attaches. The other agent in that build attaches to the running workspace.

workspace_id identifies the workspace inside this process. ttl_seconds is how long it may sit idle. seed_from copies a host directory in at start. sync_dest is where artifacts are copied back. seed_exclude is a list of skip patterns. sync_policy uses the same exclude_patterns and sync_include_patterns keys as workspace_sync_policy.

sandbox_attach_modeTools
read_write (default)execute, read_file, write_file, list_dir
read_onlyread_file, list_dir

The sandbox keys stay on the agents. The graph block does not take plugins: or sandbox:.


AgentCore ​

AgentCore runs the workspace in an Amazon Bedrock AgentCore code interpreter. Install the extra, and leave AWS credentials in the environment.

bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents-tools[agent-core-code-interpreter]==0.3.0"

agentcore.yaml:

yaml
openai:
  type: OpenAIModel
  model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"

agentcore:
  type: AgentCoreSandboxTemplate
  region: us-west-2
  session_timeout_seconds: 900

analyst:
  type: Agent
  name: agentcore_analyst
  system_prompt: Use workspace tools for files and commands.
  model: ${openai}
  sandbox_mode: sandbox
  execution_backend: ${agentcore}
  workspace_root: .
  plugins:
    - type: SandboxPlugin
python
from elsai.config import yaml_to_agent

agent = yaml_to_agent("agentcore.yaml", entry="analyst")
print(agent("Write note.txt, read it back, list the folder, and print ok."))

sandbox_mode is sandbox, not local_dev. region defaults when omitted. identifier selects a code-interpreter id. session_timeout_seconds is how long the session may run.


Daytona ​

Daytona opens a remote workspace. The client reads DAYTONA_API_KEY from the environment. Leave the key out of the file.

bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-agents-tools[sandbox-daytona]==0.3.0"
export DAYTONA_API_KEY=...

daytona.yaml:

yaml
openai:
  type: OpenAIModel
  model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"

daytona:
  type: DaytonaSandboxTemplate
  default_timeout: 900

analyst:
  type: Agent
  name: daytona_analyst
  system_prompt: Use workspace tools for files and commands.
  model: ${openai}
  sandbox_mode: sandbox
  execution_backend: ${daytona}
  workspace_root: ./daytona_workspace
  plugins:
    - type: SandboxPlugin
python
from elsai.config import yaml_to_agent

agent = yaml_to_agent("daytona.yaml", entry="analyst")
print(agent("Write note.txt, read it back, list the folder, and print ok."))

default_timeout is the command timeout in seconds. api_url and target override the Daytona host and region. sync_polling_interval is how often file sync is polled.


Backend fields ​

execution_backend and a shared sandbox’s backend use the same three types.

typeRequiredAlso acceptedInstall
LocalSandboxBackendworkspace_roottimeout, max_output_bytes, inherit_env, envelsai-agents
AgentCoreSandboxTemplateregion, identifier, session_timeout_secondselsai-agents-tools[agent-core-code-interpreter]
DaytonaSandboxTemplateapi_url, target, default_timeout, sync_polling_intervalelsai-agents-tools[sandbox-daytona]

env on a local backend is a map of strings. Put secret values in {{$VAR:}}.


Common mistakes ​

ProblemWhat to do
SandboxPlugin with no workspaceAdd execution_backend and sandbox_mode, or sandbox
sandbox_mode or execution_backend without the pluginAdd type: SandboxPlugin
sandbox: together with execution_backend, sandbox_mode, workspace_root, workspace_sync_policy, or sandbox_managerUse the direct path or the shared path
Two SandboxPlugin entriesKeep one
sandbox_output_offload without a sandboxAdd a direct or shared sandbox
local_dev with AgentCore or DaytonaUse LocalSandboxBackend, or set sandbox_mode: sandbox
sandbox_mode: offUse sandbox or local_dev

Copyright © 2026 elsai foundry.