agentsphere-sandbox
v1.0.0
Published
云端代码沙箱 SDK - 为 AI agents 提供安全的代码执行环境
Downloads
13
Maintainers
Readme
agentsphere-sandbox
云端代码沙箱 SDK - 为 AI agents 提供安全的代码执行环境
简介
这是一个强大的云端代码执行平台 SDK,专为 AI agents 和自动化系统设计。提供安全隔离的沙箱环境,支持在云端运行各种编程语言的代码。
安装
npm install agentsphere-sandbox快速开始
1. 获取 API 密钥
- 注册云沙箱服务账号
- 获取您的 API 密钥
- 设置环境变量:
SANDBOX_API_KEY=your_api_key_here2. 使用代码解释器
import { Sandbox } from 'agentsphere-sandbox'
// 创建云端沙箱实例
const sandbox = await Sandbox.create()
// 执行 Python 代码
const result = await sandbox.runCode(`
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
print(fibonacci(10))
`)
console.log(result.stdout) // 输出: 55
await sandbox.close()API 文档
核心方法
// 创建沙箱
const sandbox = await Sandbox.create(options?)
// 执行代码
const result = await sandbox.runCode(code: string)
// 文件操作
await sandbox.writeFile('/path/to/file', content)
const content = await sandbox.readFile('/path/to/file')
// 管理沙箱
await sandbox.kill() // 终止沙箱
await sandbox.close() // 关闭连接功能特性
- 🔒 安全隔离: 每个代码执行都在独立的容器环境中
- 🌐 多语言支持: Python, JavaScript, Node.js, Bash 等
- ⚡ 实时执行: 快速的代码执行和结果返回
- 📝 TypeScript: 完整的类型定义支持
- 🔄 跨平台: 支持浏览器和 Node.js 环境
- 📁 文件系统: 完整的文件读写和管理功能
- 🎯 AI 友好: 专为 AI agents 和自动化工作流设计
使用场景
- AI 代码助手: 安全执行 AI 生成的代码
- 在线代码编辑器: 构建 Web IDE 和代码演示
- 自动化测试: 在隔离环境中运行测试脚本
- 数据处理: 云端数据分析和处理管道
- 教育平台: 安全的编程学习环境
许可证
MIT License
开始使用云端沙箱,让您的应用拥有安全的代码执行能力! 🚀
