Skip to content

Network Usage

Every sandbox has a per-direction byte counter and an optional cap. You can set the cap at create time, read live counters, and raise or lift the cap while the sandbox is running.

Caps are optional fields on the create request. Either or both can be set; omit a field (or pass 0) to leave it unlimited.

const sandbox = await client.create({
image: 'ubuntu:22.04',
networkBytesInLimit: 1 * 1024 * 1024 * 1024, // 1 GiB ingress
networkBytesOutLimit: 5 * 1024 * 1024 * 1024, // 5 GiB egress
})

getNetworkUsage returns the latest cumulative counters, the active caps, and whether the quota has been exceeded.

const usage = await sandbox.getNetworkUsage()
console.log(usage.bytesIn, usage.bytesOut, usage.quotaExceeded)

The response shape:

FieldMeaning
bytes_in / bytes_outCumulative ingress / egress in bytes since the sandbox was created.
bytes_in_limit / bytes_out_limitActive cap. 0 means unlimited.
quota_exceededtrue if either direction has hit its cap. The drop rule is installed while this is true.
quota_exceeded_atRFC 3339 timestamp of when the quota was first hit. Cleared when the cap is raised.
last_sampled_atRFC 3339 timestamp of the last counter sample. Absent until the netstats poller has produced at least one sample - typically up to one poll interval after a sandbox starts.

setNetworkLimits is a PATCH - only the fields you set are changed. Pass 0 to lift a cap (back to unlimited), or a higher number to raise it. Omit a field to leave it alone.

// Raise the egress cap to 20 GiB; leave ingress alone.
const usage = await sandbox.setNetworkLimits({
networkBytesOutLimit: 20 * 1024 * 1024 * 1024,
})
// Lift the ingress cap entirely (0 = unlimited).
await sandbox.setNetworkLimits({ networkBytesInLimit: 0 })

When the new cap is above current usage, the per-IP drop is removed immediately and traffic flows again. When the new cap is still below usage, the drop stays in place until usage falls back under the limit (which only happens when you raise it further or destroy the sandbox).