@ computesdk/ 工作台
交互 REPL 用于测试 ComputeSDK 有即时反馈和自动完成的沙盒操作.
特征
- 🚀 零仪式 - 只要运行命令,没有沙盒ID管理
- ✨ 标签自动完成 - 全部100岁以上
@computesdk/cmd函数自动完成 - 🔄 提供者切换 - e2b、daytona、模式等之间的无缝交换.
- ⚡ 明智的评价 - 类型
npm.install('express')它只是运行 - 📊 实时反馈 - 立即看到时间、产出和出错
安装
npm install -D @computesdk/workbench
# Install at least one provider
npm install @computesdk/e2b
# or any other provider
快速启动
- 配置证书 内
.env数字 :
# E2B Provider
E2B_API_KEY=e2b_your_api_key_here
# Daytona Provider
DAYTONA_API_KEY=your_daytona_api_key
- 开始工作数字 :
npx workbench
- 运行命令 (自动完成的作品!):
workbench> npm.install('express')
⏳ Creating sandbox with e2b...
✅ Sandbox ready (1.2s)
Running: npm install express
✅ Completed (3.2s)
workbench> git.clone('https://github.com/user/repo')
Running: git clone https://github.com/user/repo
✅ Completed (2.1s)
workbench> ls('/home')
Running: ls /home
total 8
drwxr-xr-x 3 user user 4096 Dec 12 19:00 node_modules
drwxr-xr-x 2 user user 4096 Dec 12 19:01 repo
✅ Completed (0.1s)
图标
工作区命令
provider <name>- 交换供应商(例如,provider e2b(中文(简体) )providers- 列出所有具有地位的提供者restart- 重新启动当前沙盒destroy- 摧毁目前的沙盒info显示沙盒信息( 提供者, 上线时间)env- 显示环境/证书状况help- 显示这个帮助exit- 退出工作区
每个供应商都需要安装其软件包(例如. @computesdk/e2b并配置其证书.
运行中的命令
只要输入任意 @computesdk/cmd 函数。 Tab自动完成的工作!
软件包管理器 :
npm.install('express')
npm.run('dev')
pnpm.install()
yarn.add('lodash')
pip.install('requests')
图形 :
git.clone('https://...')
git.commit('Initial commit')
git.push()
文件系统 :
mkdir('/app/src')
ls('/home')
cat('/home/file.txt')
cp('/src', '/dest', { recursive: true })
rm('/file.txt') // Remove file
rm.rf('/directory') // Force remove anything
rm.auto('/path') // Smart remove (auto-detects file vs directory)
网络 :
curl('https://api.example.com')
wget('https://file.com/download.zip')
还有100多! 按 Tab 来探索.
提供者切换
提供者之间的切换 :
workbench> provider e2b
✅ Switched to e2b
workbench> npm.install('express')
⏳ Creating sandbox with e2b...
✅ Sandbox ready (1.2s)
Running: npm install express
✅ Completed (3.2s)
workbench> provider daytona
Destroy current sandbox? (y/N): y
✅ Switched to daytona
创建并切换沙盒
当您使用 create(),它自动成为您的当前活性沙盒。 之后所有的命令都会在这个沙盒上运行.
> create({ namespace: "h" })
✅ Switched to sandbox sandbox-123
{ instanceId: 'sandbox-123', provider: 'e2b', metadata: {} }
e2b:sandbox-123> // Prompt shows you're now on this sandbox
> ls('/home') // Runs on sandbox-123
在沙盒间切换
如果您已经有一个活性沙盒并创建了另一个沙盒, 工作台会提示您:
e2b:sandbox-456> create({ namespace: "prod" })
Switch to new sandbox? (Y/n): y
✅ Switched to sandbox sandbox-789
e2b:sandbox-789>
按 Enter 键或键入"y"来切换. 键入"n"以创建沙盒而无需切换.
标签自动完成
所有命令的自动完成工作 :
workbench> npm.<TAB>
install run init uninstall
workbench> git.<TAB>
add branch checkout clone commit diff fetch
init log pull push reset stash status
workbench> provider <TAB>
e2b daytona modal runloop vercel
支持供应商
安装任意组合 :
@computesdk/e2b- E2B沙盒@computesdk/daytona- 代托纳工作区@computesdk/modal- 模块容器@computesdk/runloop- Runloop 实例@computesdk/vercel- Vercel函数@computesdk/cloudflare- 云花岗工人@computesdk/codesandbox- 密码箱@computesdk/blaxel- 银河环境@computesdk/northflank- 北岸部署服务
环境变量
将提供者证书设置在 .env数字 :
# E2B
E2B_API_KEY=e2b_xxx
# Daytona
DAYTONA_API_KEY=xxx
# Modal
MODAL_TOKEN_ID=xxx
MODAL_TOKEN_SECRET=xxx
# Runloop
RUNLOOP_API_KEY=xxx
# Vercel
VERCEL_TOKEN=xxx
VERCEL_TEAM_ID=xxx
VERCEL_PROJECT_ID=xxx
# Cloudflare
CLOUDFLARE_SANDBOX_URL=https://sandbox.<your-subdomain>.workers.dev
CLOUDFLARE_SANDBOX_API_KEY=xxx
# CodeSandbox
CSB_API_KEY=xxx
# Blaxel
BL_API_KEY=xxx
BL_WORKSPACE=xxx
# Northflank
NORTHFLANK_TOKEN=nf_xxx
NORTHFLANK_PROJECT_ID=my-project
NORTHFLANK_TEAM_ID=xxx # optional — required only for organization API tokens
NORTHFLANK_API_URL=xxx # optional — defaults to https://api.northflank.com
提示
- 命令历史: 使用QQ/QQ箭头来导航先前的命令
- 优雅地退出: 类型
exit或者说.exit,可选择销毁沙盒 - 检查状态运行
env以查看哪些提供者的配置 - 自动创建: 第一命令自动创建沙盒
- 坚持上下文: Workbench 维护"当前沙盒" - 没有可以跟踪的ID
调试 SDK 测试
工作台为全节点.js RePL,并预装了计算SDK. 可以通过交互调用相同的方法来复制任何SDK测试.
SDK 到工作台映射
| SDK 测试代码 | 工作台等价 |
|---|---|
sandbox.runCommand('echo hi') | runCommand('echo hi') 或者说 getInstance().runCommand(...) |
sandbox.filesystem.readFile(path) | filesystem.readFile(path) |
sandbox.getInfo() | sandboxInfo() |
sandbox.getUrl({ port }) | getUrl({ port: 3000 }) |
示例: 复制失败测试
如果测试失败 :
// From provider-compatibility.test.ts
it('command with streaming callbacks', async () => {
let stdoutCalled = false;
const result = await sandbox.runCommand('echo "hello"', {
onStdout: () => { stdoutCalled = true; },
});
expect(stdoutCalled).toBe(true);
});
在工作室重现:
> ls('/home') // Auto-creates sandbox
> const sandbox = getInstance()
> let stdoutCalled = false
> const result = await sandbox.runCommand('echo "hello"', {
onStdout: (data) => { console.log('STDOUT:', data); stdoutCalled = true }
})
> stdoutCalled // Should be true
> result
声音模式
启用动词模式以查看完整的响应对象和 WebSocket 调试信息 :
> verbose() // Toggle on - shows full results and WebSocket frames
> ls('/home')
> verbose() // Toggle off
直接贝壳命令
前缀为 $ 直接运行 shell 命令( 通过) @computesdk/cmd:
> $echo "hello" | tr 'a-z' 'A-Z'
> $for i in 1 2 3; do echo $i; done
许可证
麻省理工学院