Skip to main content

Use remote sandboxes

还没翻译译自英文(docs.langchain.com)本页 49 段都还没译

Deep Agents Code uses the sandbox as tool pattern: the dcode process (LLM loop, memory, tool dispatch) runs on your machine, but agent tool calls (read_file, write_file, execute, etc.) target the remote sandbox, not your local filesystem. To get files into the sandbox, use a setup script or the provider's file transfer APIs (see Working with files).

For a deeper look at sandbox architecture, integration patterns, and security best practices, see Sandboxes.

  1. Install provider dependency

    Each built-in provider ships as an optional extra. Install one from within a session with /install, or from the shell with dcode --install. Third-party providers such as E2B install as packages with the --package flag:

    Included by default when installing deepagents-code. No extra installation needed.

    /install agentcore
    dcode --install agentcore
    /install daytona
    dcode --install daytona
    /install modal
    dcode --install modal
    /install runloop
    dcode --install runloop
    /install vercel
    dcode --install vercel

    E2B is a third-party provider published by the langchain-e2b package. Install it as a package, not a deepagents-code extra:

    /install langchain-e2b --package
    dcode --install langchain-e2b --package

    To install support for every built-in provider at once, use the all-sandboxes extra: /install all-sandboxes in a session, or dcode --install all-sandboxes from the shell. The all-sandboxes extra does not include third-party providers such as E2B.

  2. Set provider credentials

    export LANGSMITH_API_KEY="your-key"
    export AWS_ACCESS_KEY_ID="your-key"
    export AWS_SECRET_ACCESS_KEY="your-secret"
    export AWS_REGION="us-west-2"
    
    # Only when using temporary/STS credentials:
    export AWS_SESSION_TOKEN="session-token"
    export DAYTONA_API_KEY="your-key"
    modal setup
    export RUNLOOP_API_KEY="your-key"
    export VERCEL_TOKEN="your-token"
    export VERCEL_PROJECT_ID="your-project-id"
    export VERCEL_TEAM_ID="your-team-id"

    When running on Vercel, OIDC credentials are used automatically instead.

    export E2B_API_KEY="your-key"
  3. Run Deep Agents Code with a sandbox

    dcode --sandbox langsmith
    dcode --sandbox agentcore
    dcode --sandbox daytona
    dcode --sandbox modal
    dcode --sandbox runloop
    dcode --sandbox vercel
    dcode --sandbox e2b

Sandbox flags and examples

FlagDescription
--sandbox TYPESandbox provider to use. Built-ins: langsmith, agentcore, daytona, modal, runloop, vercel (default: none). Third-party and config-declared providers are also accepted. Pass --sandbox with no value to use [sandboxes].default from your config
--sandbox-id IDReuse an existing sandbox by ID instead of creating a new one. Skips creation and cleanup. Only for providers that support reattaching by ID. Refer to your sandbox documentation for more
--sandbox-snapshot-name NAMEUse or create a sandbox snapshot. Supported by langsmith, daytona, and runloop (and any third-party provider that advertises snapshot support). Cannot be combined with --sandbox-id
--sandbox-setup PATHPath to a setup script to run inside the sandbox upon creation

Each provider exposes a default working directory inside the sandbox. Setup scripts and execute commands run from this directory unless overridden:

ProviderWorking directory
LangSmith/root
AgentCore/tmp
Daytona/home/daytona
Modal/workspace
Runloop/home/user
Vercel/vercel/sandbox
E2B/home/user

Examples:

# Create a new LangSmith sandbox
dcode --sandbox langsmith

# Boot from a named snapshot (langsmith, daytona, or runloop)
dcode --sandbox daytona --sandbox-snapshot-name my-env

# Reuse an existing sandbox (skips creation and cleanup)
dcode --sandbox runloop --sandbox-id dbx_abc123

# Run a setup script after sandbox creation
dcode --sandbox modal --sandbox-setup ./setup.sh

# Use the provider set as [sandboxes].default in config
dcode --sandbox

Note

Because --sandbox accepts an optional value, keep the bare form last on the command line. Otherwise a following argument (e.g. dcode --sandbox agents) is consumed as the flag's value. Pass an explicit provider name to avoid ambiguity.

Pluggable providers

The built-in providers are not the only options. Deep Agents Code discovers sandbox providers from three sources, so you can use providers shipped by other packages or declare your own without changing Deep Agents Code:

  1. Built-in providers — LangSmith, AgentCore, Daytona, Modal, Runloop, and Vercel, shipped with deepagents-code (LangSmith by default, the others as extras).
  2. Third-party providers — published by other installed packages via a Python entry point.
  3. Config-declared providers — defined in your ~/.deepagents/config.toml.

When two sources define the same provider name, config wins over third-party entry points, which win over built-ins, so your config file can always override discovery.

Third-party providers

A package can publish a sandbox provider under the deepagents_code.sandbox_providers entry-point group. Once you install such a package, its provider is available to --sandbox automatically—no config needed:

# Install the package that publishes the provider, then use it
dcode --sandbox acme

For example, the langchain-e2b package publishes an e2b provider (see sandbox integrations). Install it as a package, set your credentials, then select it:

dcode --install langchain-e2b --package
export E2B_API_KEY="..."
dcode --sandbox e2b

If you pass a --sandbox name that is not installed or declared, Deep Agents Code lists the available providers and explains how to install or configure the missing one.

Publishing a sandbox provider

Config-declared providers

For an in-house or local provider you do not want to package, declare it under [sandboxes.providers] in ~/.deepagents/config.toml. This parallels arbitrary model providers and uses the same class_path trust model.

[sandboxes]
# Used when you run `dcode --sandbox` with no value.
default = "acme"

[sandboxes.providers.acme]
# Required: the provider class to import, in module.path:ClassName format.
class_path = "acme_sandbox.provider:AcmeProvider"
# Default working directory inside the sandbox.
working_dir = "/workspace"
# Package suggested when the provider's dependencies are missing.
package = "acme-dcode-sandbox"
# Capability flags (defaults: supports_sandbox_id = true, supports_snapshot_name = false).
supports_sandbox_id = true
supports_snapshot_name = false

# Extra keyword arguments forwarded to the provider's get_or_create().
[sandboxes.providers.acme.params]
region = "us-east-1"

class_path string

Fully-qualified provider class in module.path:ClassName format. Deep Agents Code imports and instantiates this class for the provider.

working_dir string

Default working directory inside the sandbox. Defaults to /workspace.

package string

Package name suggested in error messages when the provider's dependencies are missing.

supports_sandbox_id boolean

Whether --sandbox-id reattach is allowed for this provider. Defaults to true.

supports_snapshot_name boolean

Whether --sandbox-snapshot-name is allowed for this provider. Defaults to false.

params object

Extra keyword arguments forwarded to the provider's get_or_create().

A config entry that reuses a built-in provider's name overrides that built-in while keeping its dependency pre-flight check. Malformed entries are skipped with a warning rather than crashing startup.

Warning

Setting class_path causes Deep Agents Code to import and run arbitrary Python from the named module—module-level code executes on import. This is the same trust model as the model class_path: you control your own machine and your own config file.

Setup scripts

Use --sandbox-setup to run a shell script inside the sandbox after creation. This is useful for cloning repos, installing dependencies, and configuring environment variables.

setup.sh
#!/bin/bash
set -e

# Clone repository using GitHub token
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/username/repo.git $HOME/workspace
cd $HOME/workspace

# Make environment variables persistent
cat >> ~/.bashrc <<'EOF'
export GITHUB_TOKEN="${GITHUB_TOKEN}"
export OPENAI_API_KEY="${OPENAI_API_KEY}"
cd $HOME/workspace
EOF
source ~/.bashrc

Deep Agents Code expands ${VAR} references in setup scripts using your local environment variables. Store secrets in a local .env file for the setup script to access.

Warning

Sandboxes isolate code execution, but agents remain vulnerable to prompt injection with untrusted inputs. Use human-in-the-loop approval, short-lived secrets, and trusted setup scripts only. See Security considerations for details.