Skill flagged — suspicious patterns detected

ClawHub Security flagged this skill as suspicious. Review the scan results before using.

Sandbox Manager

v1.0.0

百度 Agent Sandbox 沙箱管理。触发词:沙箱/sandbox/创建沙箱/沙箱实例/沙箱模板/code_test/browser_use/aio。

0· 26· 1 versions· 0 current· 0 all-time· Updated 5h ago· MIT-0

沙箱管理 Skill

百度 Agent Sandbox 沙箱创建和管理技能,支持快速创建、连接、管理沙箱实例。

核心功能:

  • ✅ 快速创建沙箱实例(支持多种模板)
  • ✅ 查询沙箱状态和信息
  • ✅ 连接已有沙箱实例
  • ✅ 沙箱生命周期管理(创建、启动、停止、销毁)
  • ✅ 自动配置 API Key 和环境

沙箱模板说明

模板名称用途特性
code_test代码执行沙箱支持多语言代码执行、终端操作
browser_use浏览器自动化沙箱支持浏览器操作、网页测试
aioAll-In-One 全栈沙箱浏览器 + 代码执行 + 终端
coding_agent编码助手沙箱内置 Zulu、Ducc 等 DevOps 工具

快速开始

1. 首次使用 - 配置 API Key

获取 API Key:

  1. 访问 OneTool 沙箱管理页面
  2. 创建团队或个人空间
  3. 进入空间后在『沙箱』模块点击『API Key 管理』
  4. 获取你的 API Key

配置 API Key:

# Agent 会自动将 API Key 写入 ~/.env 文件
# 格式如下:
E2B_API_KEY=<your_api_key>
E2B_DOMAIN=agent-sandbox.baidu-int.com

2. 安装依赖

pip3.9 install e2b==1.11.2+baidu --index=https://pip.baidu-int.com/simple/
pip3.9 install e2b-code-interpreter==1.5.2 --index=https://pip.baidu-int.com/simple/
pip3.9 install load_dotenv==0.1.0 --index=https://pip.baidu-int.com/simple/

使用方式

方式一: 通过 Agent 自然语言创建

直接对 Agent 说:

  • "创建一个沙箱,模板使用 code_test"
  • "帮我创建一个浏览器沙箱"
  • "创建一个 aio 沙箱,时长 2 小时"

Agent 会自动:

  1. 检查 API Key 配置
  2. 安装必要依赖
  3. 创建沙箱实例
  4. 返回沙箱访问地址和 ID

方式二: 通过命令行创建

cd ~/.openclaw/workspace/skills/sandbox-manager
python3.9 scripts/create_sandbox.py --template code_test --timeout 3600

核心命令

创建沙箱

from e2b_code_interpreter import Sandbox
from dotenv import load_dotenv

load_dotenv()

# 创建沙箱
sbx = Sandbox(
    timeout=3600,  # 1小时
    template="code_test",  # 模板名称
    metadata={
        "agent-sandbox/creator": "caojiao",
        "agent-sandbox/name": "my-sandbox"
    }
)

print(f"沙箱ID: {sbx.sandbox_id}")
print(f"管理页面: https://8080-{sbx.sandbox_id}.agent-sandbox.baidu-int.com/")

连接已有沙箱

from e2b_code_interpreter import Sandbox

# 通过 sandbox_id 连接
sbx = Sandbox(sandbox_id="al7hwm9s")

# 执行命令
result = sbx.commands.run("ls -la")
print(result.stdout)

查询沙箱信息

info = sbx.get_info()
print(f"沙箱ID: {info.sandbox_id}")
print(f"模板: {info.template_id}")
print(f"过期时间: {info.end_at}")
print(f"日志链接: {info.metadata.get('logURL')}")

销毁沙箱

sbx.kill()  # 立即销毁

沙箱能力

1. 代码执行

# 执行 Python 代码
result = sbx.run_code(
    language="python",
    code="print('Hello, World!')"
)

# 执行 Shell 命令
result = sbx.commands.run("git clone ...")

2. 文件操作

# 写入文件
sbx.files.write("test.txt", "Hello, Sandbox!")

# 读取文件
content = sbx.files.read("test.txt")

# 列出文件
files = sbx.files.list(path=".", depth=2)

3. 服务暴露

沙箱内启动的服务会自动暴露:

http://{port}-{sandboxId}.agent-sandbox.baidu-int.com

示例:

# 启动 HTTP 服务
sbx.commands.run("python -m SimpleHTTPServer 8080", background=True)

# 访问地址: http://8080-{sandboxId}.agent-sandbox.baidu-int.com

API 参考

Sandbox 参数

参数类型说明默认值
timeoutint沙箱存活时间(秒),最大 86400(1天)600
templatestr沙箱模板名称必填
sandbox_idstr已有沙箱ID(用于连接)可选
metadatadict沙箱元数据可选
envsdict环境变量可选
request_timeoutint请求超时时间(秒)600

常用方法

方法说明
sbx.commands.run(cmd)执行命令
sbx.files.read(path)读取文件
sbx.files.write(path, content)写入文件
sbx.files.list(path)列出文件
sbx.run_code(language, code)执行代码
sbx.get_info()获取沙箱信息
sbx.kill()销毁沙箱

注意事项

  1. 沙箱存活时间: 最大 1 天(86400 秒),超时自动销毁
  2. 计费: 不同规格沙箱产生不同费用,注意运行时长
  3. 权限注入: 需要提供 COMATE_AUTH_TOKEN 才能访问 iCode 等内部服务
  4. 网络访问: 沙箱出站流量受限(白名单机制)
  5. 数据持久化: 沙箱销毁后数据丢失,重要数据需提前保存

相关链接

联系人


创建时间: 2026-04-29 创建人: caojiao 的数字助手 雀雀

Version tags

latestvk976evvq4jtszqbsqkj6tjywxs85vmpn