Deep Agents Code 使用 sandbox as tool pattern:dcode process(LLM loop、memory、tool dispatch)在你的机器上运行,但 agent tool calls(read_filewrite_fileexecute 等)会面向 remote sandbox,而不是你的 local filesystem。若要将 files 放入 sandbox,请使用 setup script 或 provider 的 file transfer APIs(请参阅 Working with files)。 若要深入了解 sandbox architecture、integration patterns 和 security best practices,请参阅 Sandboxes

安装 provider dependency

安装 deepagents-code 时默认包含。无需额外安装。
若要一次性安装对所有 sandbox providers 的支持,请使用 all-sandboxes extra:uv tool install 'deepagents-code[all-sandboxes]'

设置 provider credentials

export LANGSMITH_API_KEY="your-key"

使用 sandbox 运行 Deep Agents Code

dcode --sandbox langsmith

Sandbox flags 和 examples

FlagDescription
--sandbox TYPE要使用的 sandbox provider:langsmithagentcoremodaldaytonarunloop(default:none
--sandbox-id ID通过 ID 复用现有 sandbox,而不是创建新 sandbox。跳过 creation 和 cleanup。更多信息请参阅你的 sandbox documentation
--sandbox-snapshot-name NAME使用或创建 sandbox snapshot(仅 LangSmith)。不能与 --sandbox-id 组合使用
--sandbox-setup PATHSandbox 创建后要在其中运行的 setup script path
每个 provider 都会在 sandbox 内暴露 default working directory。除非覆盖,否则 setup scripts 和 execute commands 会从此 directory 运行:
ProviderWorking directory
LangSmith/root
Daytona/home/daytona
Modal/workspace
Runloop/home/user
AgentCore/tmp
Examples:
# Create a new Daytona sandbox
dcode --sandbox daytona

# 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

Setup scripts

使用 --sandbox-setup 在 sandbox 创建后在其中运行 shell script。这适用于 clone repos、安装 dependencies 和配置 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 会使用你的 local environment variables 展开 setup scripts 中的 ${VAR} references。将 secrets 存储在 local .env file 中,供 setup script 访问。
Sandboxes 会隔离 code execution,但 agents 仍然容易受到 untrusted inputs 中 prompt injection 的影响。仅使用 human-in-the-loop approval、short-lived secrets 和可信 setup scripts。详情请参阅 Security considerations