Skip to content

Commit 831329d

Browse files
authored
docs: add instructions for using the sandbox tool (#308)
1 parent 56087ef commit 831329d

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

docs/content/5.tools/3.sandbox-tools.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,73 @@ navigation:
55
icon: i-lucide-codesandbox
66
---
77

8-
提供多种沙箱工具:
8+
## 概述
99

10+
VeADK 提供多种沙箱工具,为 Agent 的执行与操作提供安全、隔离的运行环境。目前支持以下几种类型:
11+
- Code sandbox
1012
- Computer sandbox (TBD)
1113
- Browser sandbox (TBD)
12-
- Code sandbox (TBD)
14+
15+
当前,VeADK 支持两种方式调用 Code Sandbox:
16+
- (推荐)内建工具 [`run_code`](https://www.volcengine.com/docs/86681/1847934):该方式通过 AgentKit tools 调用,配置过程可自定义代码生成模型。通过设置环境变量 `AGENTKIT_TOOL_ID` 或者在 config.yaml 中添加配置即可开始使用:
17+
```yaml
18+
agentkit:
19+
tool:
20+
id: <your_id>
21+
```
22+
- MCP 工具 [`code_sandbox`](https://www.volcengine.com/mcp-marketplace/detail?name=Code-Sandbox%20MCP):该方式通过 MCP(Model Context Protocol) 调用 Code Sandbox 工具,具体步骤为:
23+
- 在 VeFaaS 一键部署 [Code Sandbox Agent 应用](https://www.volcengine.com/docs/6662/1538139),配置过程中可自定义代码生成模型;
24+
- 部署成功后,在部署的 Code sanbox 的应用详情标签页获取**访问地址**,地址形式是:{YOUR_URL}/?token={YOUR_TOKEN};
25+
- 为 Code sandbox [创建 MCP Server](https://www.volcengine.com/mcp-marketplace/detail?name=Code-Sandbox%20MCP) 并配置环境变量:
26+
```bash
27+
SANDBOX_API={YOUR_URL}
28+
AUTH_TOKEN={YOUR_TOKEN}
29+
```
30+
- 最后,将上述 Code sanbox 访问地址设置环境变量 `TOOL_CODE_SANDBOX_URL` 或者在 config.yaml 中添加配置即可开始使用:
31+
```yaml
32+
tool:
33+
code_sandbox:
34+
url: <your_url>
35+
```
36+
37+
38+
## 使用
39+
以下示例展示了在 VeADK 中如何通过两种方式调用沙箱工具来执行代码。
40+
41+
示例一:使用内建工具 `run_code`:
42+
43+
```python [agent.py]
44+
import asyncio
45+
from veadk import Agent, Runner
46+
from veadk.tools.builtin_tools.run_code import run_code
47+
48+
agent = Agent(
49+
instruction="你是一名资深的代码专家。请通过调用 run_code 工具执行代码、调试、并展示运行结果。",
50+
tools=[run_code]
51+
)
52+
53+
runner = Runner(agent=agent)
54+
55+
response = asyncio.run(runner.run(messages="请用Python写一个函数,计算斐波那契数列的前10项,并打印出来。"))
56+
57+
print(response)
58+
```
59+
60+
示例二:使用 MCP 工具 `code_sandbox`
61+
62+
```python [agent.py]
63+
import asyncio
64+
from veadk import Agent, Runner
65+
from veadk.tools.sandbox.code_sandbox import code_sandbox
66+
67+
agent = Agent(
68+
instruction="你是一名资深的代码专家。请通过调用 code_sandbox 工具执行代码、调试、并展示运行结果。",
69+
tools=[code_sandbox]
70+
)
71+
72+
runner = Runner(agent=agent)
73+
74+
response = asyncio.run(runner.run(messages="请用Python写一个函数,计算斐波那契数列的前10项,并打印出来。"))
75+
76+
print(response)
77+
```

0 commit comments

Comments
 (0)