@tcb-sandbox/e2b-sandbox-adapter
v0.3.13
Published
Local adapter/proxy that bridges E2B SDK to tcb-remote-workspace, handling path rewriting and session header injection.
Downloads
274
Maintainers
Readme
@tcb-sandbox/e2b-sandbox-adapter
E2B SDK 适配代理,让标准 E2B SDK 透明连接到 TRW。
安装
pnpm add @tcb-sandbox/e2b-sandbox-adapter e2b快速开始
import { startAdapter } from "@tcb-sandbox/e2b-sandbox-adapter"
import { Sandbox } from "e2b"
const adapter = await startAdapter({
endpoint: "https://your-gateway.com",
sessionId: "your-session-id",
})
const sandbox = new Sandbox({
sandboxId: "any",
debug: true,
envdVersion: "99.99.99",
})
// 文件操作
await sandbox.files.write("hello.txt", "Hello!")
const content = await sandbox.files.read("hello.txt")
// 命令执行
const result = await sandbox.commands.run("echo hello")
console.log(result.stdout)
await adapter.close()架构
E2B SDK → 127.0.0.1:49983 → adapter → TRW /e2b-compatible/*Adapter 自动处理:
- 路径改写:
/health→/e2b-compatible/health - Header 注入:
X-Cloudbase-Session-Id - 全双工流式转发
API
startAdapter(options)
| 参数 | 必填 | 默认值 | 说明 |
|------|:----:|--------|------|
| endpoint | ✅ | - | TRW 网关 URL |
| sessionId | ✅ | - | Session ID |
| pathPrefix | - | /e2b-compatible | 路径前缀 |
| port | - | 49983 | 代理端口 |
| adminPort | - | 49984 | 管理 API 端口 |
| host | - | 127.0.0.1 | 绑定地址 |
| logLevel | - | warn | 日志级别 |
AdapterHandle
| 属性/方法 | 说明 |
|-----------|------|
| setSessionId(value) | 热更新 session |
| setEndpoint(value) | 热更新 endpoint |
| close() | 优雅关闭 |
运行时热更新
// 直接调用方法
adapter.setSessionId("new-session-id")
adapter.setEndpoint("https://new-gateway.com")或通过 Management API:
curl -X PUT http://127.0.0.1:49984/_admin/config \
-d '{"sessionId": "new", "endpoint": "https://new.com"}'CLI 模式
pnpm dlx @tcb-sandbox/e2b-sandbox-adapter \
--endpoint https://your-gateway.com \
--session-id your-session-id限制
- 仅数据面(
Sandbox.connect/create不支持) - 必须使用 adapter(SDK 不能直连)
StreamInput未实现- 输出上限 10 MB
E2B SDK 注意(2.14+)
- 设置
envdVersion: "99.99.99" sendStdin需stdin: true启动
