The sandbox metrics allows you to get information about the sandbox’s CPU and memory usage.

Getting sandbox metrics

Getting the metrics of a sandbox returns an array of timestamped metrics containing CPU and memory usage information. The metrics are collected at the start of the sandbox, then every 2 seconds, and finally right before the sandbox is deleted.

Getting sandbox metrics using the SDKs

import { Sandbox } from 'novita-sandbox/code-interpreter'

const sandbox = await Sandbox.create()
console.log('Sandbox created', sandbox.sandboxId)

let metrics = await sandbox.getMetrics()

// You can also get the metrics by sandbox ID:
// const metrics = await Sandbox.getMetrics(sbx.sandboxId)

while (metrics && metrics.length <= 1) {
    console.log('Waiting for metrics...')
    await new Promise(resolve => setTimeout(resolve, 1000))
    metrics = await sandbox.getMetrics()
}

console.log('Sandbox metrics:', metrics)

// Example output:
// Sandbox metrics: [
//   {
//     cpuCount: 2,
//     cpuUsedPct: 17.85,
//     memTotalMiB: 987,
//     memUsedMiB: 245,
//     timestamp: '2025-06-30T06:49:15.243Z'
//   },
//   {
//     cpuCount: 2,
//     cpuUsedPct: 0.4,
//     memTotalMiB: 987,
//     memUsedMiB: 246,
//     timestamp: '2025-06-30T06:49:20.237Z'
//   }
// ]

await sandbox.kill()

Getting sandbox metrics using the CLI

Bash
novita-sandbox-cli sandbox metrics <sandbox_id>

Limitations

  • It may take a second or more to get the metrics after the sandbox is created. Until the logs are collected from the sandbox, you will get an empty array.