> ## Documentation Index
> Fetch the complete documentation index at: https://nvd-54.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用远程沙箱

> 在 LangSmith、Daytona、Modal、Runloop 或 AgentCore 沙箱中运行深度智能体 CLI 工具执行。安装提供商扩展、设置凭证，以及使用标志和设置脚本。

CLI 使用[沙箱即工具](/oss/python/deepagents/sandboxes#sandbox-as-tool-pattern)模式：CLI 进程（大语言模型（LLM）循环、记忆、工具调度）在你的本地机器上运行，但智能体工具调用（`read_file`、`write_file`、`execute` 等）指向远程沙箱，而不是你的本地文件系统。要将文件导入沙箱，请使用[设置脚本](#setup-scripts)或提供商的文件传输 API（参见[使用文件](/oss/python/deepagents/sandboxes#working-with-files)）。

有关沙箱架构、集成模式和安全最佳实践的深入了解，请参见[沙箱](/oss/python/deepagents/sandboxes)。

<Steps>
  <Step title="安装提供商依赖" icon="download">
    <Tabs>
      <Tab title="LangSmith">
        安装 `deepagents-cli` 时默认包含。无需额外安装。
      </Tab>

      <Tab title="Daytona">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        uv tool install deepagents-cli --with langchain-daytona
        ```
      </Tab>

      <Tab title="Modal">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        uv tool install deepagents-cli --with langchain-modal
        ```
      </Tab>

      <Tab title="Runloop">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        uv tool install deepagents-cli --with langchain-runloop
        ```
      </Tab>

      <Tab title="AgentCore">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        uv tool install deepagents-cli --with langchain-agentcore-codeinterpreter
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="设置提供商凭证" icon="key">
    <Tabs>
      <Tab title="LangSmith">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        export LANGSMITH_API_KEY="your-key"
        ```
      </Tab>

      <Tab title="Daytona">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        export DAYTONA_API_KEY="your-key"
        ```
      </Tab>

      <Tab title="Modal">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        modal setup
        ```
      </Tab>

      <Tab title="Runloop">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        export RUNLOOP_API_KEY="your-key"
        ```
      </Tab>

      <Tab title="AgentCore">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        export AWS_ACCESS_KEY_ID="your-key"
        export AWS_SECRET_ACCESS_KEY="your-secret"
        export AWS_SESSION_TOKEN="session-token"
        export AWS_REGION="us-west-2"
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="使用沙箱运行 CLI" icon="player-play">
    <Tabs>
      <Tab title="LangSmith">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        deepagents --sandbox langsmith
        ```
      </Tab>

      <Tab title="Daytona">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        deepagents --sandbox daytona
        ```
      </Tab>

      <Tab title="Modal">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        deepagents --sandbox modal
        ```
      </Tab>

      <Tab title="Runloop">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        deepagents --sandbox runloop
        ```
      </Tab>

      <Tab title="AgentCore">
        ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
        deepagents --sandbox agentcore
        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>

## 沙箱标志和示例

| 标志                     | 说明                                                                        |
| ---------------------- | ------------------------------------------------------------------------- |
| `--sandbox TYPE`       | 使用的沙箱提供商：`langsmith`、`agentcore`、`modal`、`daytona` 或 `runloop`（默认：`none`） |
| `--sandbox-id ID`      | 通过 ID 复用现有沙箱而非创建新沙箱。跳过创建和清理。详情请参考你的沙箱文档                                   |
| `--sandbox-setup PATH` | 沙箱创建后在其内部运行的设置脚本路径                                                        |

示例：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# 创建新的 Daytona 沙箱
deepagents --sandbox daytona

# 复用现有沙箱（跳过创建和清理）
deepagents --sandbox runloop --sandbox-id dbx_abc123

# 沙箱创建后运行设置脚本
deepagents --sandbox modal --sandbox-setup ./setup.sh
```

## 设置脚本

使用 `--sandbox-setup` 在沙箱创建后运行 shell 脚本。这对于克隆仓库、安装依赖和配置环境变量非常有用。

```bash title="setup.sh" theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
#!/bin/bash
set -e

# 使用 GitHub token 克隆仓库
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/username/repo.git $HOME/workspace
cd $HOME/workspace

# 使环境变量持久化
cat >> ~/.bashrc <<'EOF'
export GITHUB_TOKEN="${GITHUB_TOKEN}"
export OPENAI_API_KEY="${OPENAI_API_KEY}"
cd $HOME/workspace
EOF
source ~/.bashrc
```

CLI 会使用你本地的环境变量来展开设置脚本中的 `${VAR}` 引用。将密钥存储在本地 `.env` 文件中供设置脚本访问。

<Warning>
  沙箱隔离了代码执行，但智能体在处理不受信任的输入时仍然容易受到提示注入攻击。请使用人机协作审批、短期密钥，且仅使用受信任的设置脚本。详情请参见[安全注意事项](/oss/python/deepagents/sandboxes#security-considerations)。
</Warning>

***

<div className="source-links">
  <Callout icon="terminal-2">
    [连接这些文档](/use-these-docs)到 Claude、VSCode 等工具，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/deepagents/cli/remote-sandboxes.mdx)或[提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
