> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/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="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\python\integrations\sandboxes\runloop.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
