> ## 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.

# 沙盒模板

> 使用模板定义沙盒的容器镜像、资源限制和配置。

<Warning>
  沙盒处于私有预览阶段。随着迭代，API 和功能可能会发生变化。[加入等待名单](https://www.langchain.com/langsmith-sandboxes-waitlist?ref=docs.langchain.com) 以获取访问权限。
</Warning>

在创建沙盒之前，你需要一个**模板**。模板定义了沙盒实例的蓝图，包括容器镜像、资源分配以及可选配置，如卷和身份验证代理规则。

<img src="https://mintcdn.com/hhh-8c10bf0c/1xJTbE4Z922F2hsr/images/langsmith/sandboxes/sb-templates.png?fit=max&auto=format&n=1xJTbE4Z922F2hsr&q=85&s=4a8fb4235df5e56a5adcc3e6f8092814" alt="模板列表视图" width="3206" height="942" data-path="images/langsmith/sandboxes/sb-templates.png" />

## 模板定义的内容

| 设置项          | 描述                                                            |
| ------------ | ------------------------------------------------------------- |
| **容器镜像**     | 要使用的 Docker 镜像（支持私有仓库）                                        |
| **资源容量**     | CPU、内存和存储限制                                                   |
| **卷**        | 要附加的持久化存储（可选）                                                 |
| **身份验证代理配置** | 用于将密钥注入出站请求的规则（可选）——参见[身份验证代理](/langsmith/sandbox-auth-proxy) |

## 创建模板

<CodeGroup>
  ```python Python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  from langsmith.sandbox import SandboxClient

  client = SandboxClient()

  client.create_template(
      name="python-sandbox",
      image="python:3.12-slim",
  )
  ```

  ```ts TypeScript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  import { SandboxClient } from "langsmith/experimental/sandbox";

  const client = new SandboxClient();

  await client.createTemplate("node-sandbox", {
    image: "node:20-slim",
  });
  ```
</CodeGroup>

你也可以通过 REST API 创建模板，并完全控制资源和代理配置：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
curl -X POST "$LANGSMITH_ENDPOINT/api/v2/sandboxes/templates" \
  -H "x-api-key: $LANGSMITH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "python-sandbox",
    "image": "python:3.12-slim",
    "resources": {"cpu": "500m", "memory": "512Mi", "storage": "2Gi"}
  }'
```

## 后续步骤

* 从你的模板[创建沙盒](/langsmith/sandbox-sdk)
* [配置身份验证代理规则](/langsmith/sandbox-auth-proxy)以将密钥注入出站请求
* [设置预热池](/langsmith/sandbox-warm-pools)以预置沙盒，实现更快的启动速度

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\langsmith\sandbox-templates.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>
