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

The sandbox “Monitoring Metrics” feature is currently in Beta testing. You need to install the beta version of the SDK or beta version of the CLI to use it.

Installation

To get sandbox metrics, you need to install the beta version of the SDKs and CLI:

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 '@e2b/code-interpreter'

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

const metrics = await sbx.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 sbx.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'
//   }
// ]

Getting sandbox metrics using the CLI

Bash
e2b sandbox metrics <sandbox_id>

Limitations while in beta

  • 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.