import { Sandbox } from '@e2b/code-interpreter'
const sbx = await Sandbox.create()
console.log('Sandbox created', sbx.sandboxId)
let metrics = await sbx.getMetrics()
// 您也可以通过指定沙箱 ID 来获取指标信息
// const metrics = await Sandbox.getMetrics(sandboxId)
while (metrics && metrics.length <= 1) {
console.log('Waiting for metrics...')
await new Promise(resolve => setTimeout(resolve, 1000))
metrics = await sbx.getMetrics()
}
console.log('Sandbox metrics:', metrics)
// 输出示例:
// Sandbox metrics: [
// {
// cpuCount: 2,
// cpuUsedPct: 15.92,
// memTotalMiB: 987,
// memUsedMiB: 245,
// timestamp: '2025-06-22T06:54:28.234Z'
// },
// {
// cpuCount: 2,
// cpuUsedPct: 0.8,
// memTotalMiB: 987,
// memUsedMiB: 246,
// timestamp: '2025-06-22T06:54:33.232Z'
// }
// ]