简体中文
import { Sandbox } from '@e2b/code-interpreter' // 创建一个沙箱,并保持运行 60 秒。 const sandbox = await Sandbox.create({ timeoutMs: 60_000, // 单位为毫秒。 })
import { Sandbox } from '@e2b/code-interpreter' // 创建一个沙箱,并保持运行 60 秒。 const sandbox = await Sandbox.create({ timeoutMs: 60_000 }) // 更改沙箱超时时间为 30 秒(从方法执行后开始计时)。 await sandbox.setTimeout(30_000)
import { Sandbox } from '@e2b/code-interpreter' // 创建一个沙箱,并保持运行 60 秒。 const sandbox = await Sandbox.create({ timeoutMs: 60_000 }) // 获取沙箱信息。 const info = await sandbox.getInfo() console.log(info) // 输出结果示例: // { // sandboxId: 'i2n8dnaa31gr4yo6ykf7r-1e67fa95', // templateId: 'uhop43uji8fr7qkfbmsp', // name: 'code-interpreter-v1', // metadata: {}, // envdVersion: '0.2.0', // envdAccessToken: undefined, // startedAt: 2025-06-21T09:13:01.116Z, // endAt: 2025-06-21T09:14:01.116Z // }
kill
import { Sandbox } from '@e2b/code-interpreter' // 创建一个沙箱,并保持运行 60 秒。 const sandbox = await Sandbox.create({ timeoutMs: 60_000 }) // 立即关闭沙箱。 await sandbox.kill()