@ computesdk/isorun
伊索伦语Name 提供方 计算SDK. 被隔离的 Linux VM 沙盒用于运行不可信和AI生成的代码,由第二台计费.
安装
npm install @computesdk/isorun
使用量
import { isorun } from '@computesdk/isorun'
const compute = isorun({
apiKey: process.env.ISORUN_API_KEY,
})
const sandbox = await compute.instances.create({ runtime: 'node' })
const result = await sandbox.runCommand('node -v')
console.log(result.stdout) // v22.x.x
await sandbox.filesystem.writeFile('/tmp/hello.txt', 'world')
const content = await sandbox.filesystem.readFile('/tmp/hello.txt')
await sandbox.destroy()
配置
| 选项 | 新闻 var | 默认 | 说明 |
|---|---|---|---|
apiKey | ISORUN_API_KEY | 所需经费 | API 密钥从 (原始内容存档于2018-10-21). app.isorun.ai |
沙盒 API
// Execute commands
const cmd = await sandbox.runCommand('echo hello', { env: { FOO: 'bar' }, cwd: '/tmp' })
// Filesystem
await sandbox.filesystem.writeFile('/app/data.json', JSON.stringify({ key: 'value' }))
const data = await sandbox.filesystem.readFile('/app/data.json')
const entries = await sandbox.filesystem.readdir('/app')
const exists = await sandbox.filesystem.exists('/app/data.json')
await sandbox.filesystem.mkdir('/app/output')
await sandbox.filesystem.remove('/app/output')
// Lifecycle
const info = await sandbox.getInfo()
const all = await compute.instances.list()
await sandbox.destroy()
标准接口之外
这个 isorun SDK暴露出一些在标准计算SDK接口中没有插槽的能力——分叉(sandbox.fork(n)),休眠/休眠(sandbox.hibernate() 编号 : sandbox.resume()),并重新设置超时(sandbox.setTimeout(seconds)) (中文(简体) ). 通过以下方式达到基本实例:
const native = sandbox.getInstance() // returns the raw Sandbox
await native.fork(4)
await native.hibernate()