简体中文
NotFoundError
NotFoundException
import { Sandbox } from '@e2b/code-interpreter' // or import { Sandbox } from 'e2b' // or import { Sandbox } from '@e2b/desktop' const sbx = await Sandbox.create() console.log('Sandbox created', sbx.sandboxId) // 暂停沙箱 // 建议您将沙箱 ID 保存到数据库中,以便稍后恢复沙箱。 const sandboxId = await sbx.pause() console.log('Sandbox paused', sandboxId)
import { Sandbox } from '@e2b/code-interpreter' // or import { Sandbox } from 'e2b' // or import { Sandbox } from '@e2b/desktop' const sbx = await Sandbox.create() console.log('Sandbox created', sbx.sandboxId) // 暂停沙箱 // 建议您将沙箱 ID 保存到数据库中,以便稍后恢复沙箱。 const sandboxId = await sbx.pause() console.log('Sandbox paused', sandboxId) // 恢复沙箱 const sameSbx = await Sandbox.resume(sandboxId) console.log('Sandbox resumed', sameSbx.sandboxId)
import { Sandbox } from '@e2b/code-interpreter' // or import { Sandbox } from 'e2b' // or import { Sandbox } from '@e2b/desktop' const sbx = await Sandbox.resume(sandboxId, { timeoutMs: 60 * 1000 }) // 60 秒
import { Sandbox, SandboxInfo } from '@e2b/code-interpreter' // or import { Sandbox, SandboxInfo } from 'e2b' // or import { Sandbox, SandboxInfo } from '@e2b/desktop' // 过滤出所有被暂停的沙箱 const paginator = Sandbox.list({ query: { state: ['paused'] } }) // 分页获取所有被暂停的沙箱 const sandboxes: SandboxInfo[] = [] while (paginator.hasNext) { const items = await paginator.nextItems() sandboxes.push(...items) } console.log('all paused sandboxes', sandboxes)
kill
import { Sandbox } from '@e2b/code-interpreter' // or import { Sandbox } from 'e2b' // or import { Sandbox } from '@e2b/desktop' const sbx = await Sandbox.create() console.log('Sandbox created', sbx.sandboxId) // 暂停沙箱 const sandboxId = await sbx.pause() // 删除被暂停的沙箱 await sbx.kill() // 或者通过指定沙箱 ID 来删除被暂停的沙箱 // await Sandbox.kill(sandboxId)