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

# RunloopSandbox 集成

> 使用 LangChain Python 与 RunloopSandbox 沙箱后端集成。

[Runloop](https://www.runloop.ai/) 提供用于在隔离环境中运行代码的一次性开发环境。有关注册、认证和平台详情，请参阅 [Runloop 文档](https://docs.runloop.ai/)。

## 安装

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-runloop
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-runloop
  ```
</CodeGroup>

## 创建沙箱后端

在 Python 中，你使用提供商 SDK 创建开发环境，然后用 [deepagents 后端](/oss/python/deepagents/backends) 将其包装。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from runloop_api_client import RunloopSDK

from langchain_runloop import RunloopSandbox

api_key = "..."
client = RunloopSDK(bearer_token=api_key)

devbox = client.devbox.create()
backend = RunloopSandbox(devbox=devbox)

try:
    result = backend.execute("echo hello")
    print(result.output)
finally:
    devbox.shutdown()
```

## 与 Deep Agents 一起使用

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from runloop_api_client import RunloopSDK
from langchain_anthropic import ChatAnthropic

from deepagents import create_deep_agent
from langchain_runloop import RunloopSandbox

api_key = "..."
client = RunloopSDK(bearer_token=api_key)

devbox = client.devbox.create()
backend = RunloopSandbox(devbox=devbox)

agent = create_deep_agent(
    model=ChatAnthropic(model="claude-sonnet-4-20250514"),
    system_prompt="You are a coding assistant with sandbox access.",
    backend=backend,
)

try:
    result = agent.invoke(
        {"messages": [{"role": "user", "content": "Create a small Python project and run tests"}]}
    )
finally:
    devbox.shutdown()
```

## 清理

完成后务必关闭开发环境，以避免持续的资源使用。

另请参阅：[沙箱](/oss/python/deepagents/sandboxes)。

***

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

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