Runtime (withruntime.com) bills an agent sandbox on the CPU it actually uses, $0.03 per active vCPU-hour, and pauses it after 300 seconds with nothing happening, so the most common runaway, a machine nobody is using, costs almost nothing by default. The other four need a limit you set. This post covers each way an agent can spend money it should not. It calculates the worst case for one day and shows the limit that stops it. It also covers which limits an agent can change on its own, and the one it cannot change.
Why are agents worse at spending than people?
An agent does not feel that something is taking too long. A person notices a laptop fan, a slow terminal or a bill alert. An agent retries what failed, starts another sandbox when one is busy, and keeps going until something stops it. Each failure below is normal agent behavior, not a bug. Each one has caused a surprise bill somewhere.
The worst cases in this post use a 2 vCPU, 4 GiB sandbox, which costs $0.09 an hour with both CPUs working and $0.035 an hour while it waits, at Runtime's published rates (pricing).
1. What does a forgotten sandbox cost?
On most clouds, the bill covers a full day of running time. On Runtime, it
covers a minute of running time, then storage. An agent creates a sandbox. The
task ends or the process crashes. Nothing calls delete(). The machine keeps its
memory reserved, and the meter keeps running.
- Without a limit 24 hours waiting cost $0.84, and a fleet of a hundred forgotten ones $84 a day.
- With the default idle pause after 300 seconds with no request, no running command, no open connection and no CPU use, the sandbox pauses itself, and you pay only for its saved state. Two GB of it cost $0.0120 a day.
The limit: keep idlePauseSeconds low, from 60 seconds up.
Create sandboxes in a scope that deletes them: await using in TypeScript, or
with in Python. Give every sandbox a task creates a label, so a cleanup job
can find any sandbox the scope missed (pause when idle).
2. What happens when an agent loops on create?
It fills your account. An agent whose tool call times out tries again. A planner that thinks a sandbox is busy starts another. A framework retries a failed step on a new machine each time. Each attempt creates a new sandbox, and each one spends its time installing the same dependencies.
- Without a limit a paid account runs 100 sandboxes at the same time. If all of them are busy for a day, they cost $221.
- With limits an idempotency key built from the task id makes a retried create return the sandbox it already made, not a second one. The size of each sandbox is a constant in your code, not a tool argument. So an agent cannot request 16 vCPUs and 64 GiB because a build was slow. A daily spending limit on the agent's key (below) caps a loop you did not expect.
The Runtime SDKs already send an idempotency key with every write, so a retry inside one process never duplicates a create. Pass your own key to cover a process that restarts (retry safely).
3. What does a runaway process cost?
The machine can burn as much as it has. A test that loops forever, a crawler that never reaches its stop condition, or a compile in a loop: the sandbox is not idle, so it never pauses. On a busy machine, billing for CPU use does not help.
- Without a limit the largest sandbox, 16 vCPUs and 64 GiB, fully busy for a day costs $24.
- With limits
timeoutSecondson each command ends that command.maxCostat create caps the whole sandbox: once it has cost that much, it pauses with its memory and disk kept, and compute billing stops with it. It starts again only when someone raises itsmaxCost. A sandbox with amaxCostof"0.50"costs at most $0.50 of compute, whatever runs inside it.
Give every command a timeout that fits its step. A test run that normally
takes two minutes gets ten minutes, not the 24 hours a streamed command may run.
Give every task sandbox a maxCost that fits the task.
4. How does storage pile up?
Storage grows one snapshot at a time, and people rarely check it, because no single item is expensive. Suppose an agent takes a snapshot after each of 50 steps in a task, and runs 20 tasks a day. A snapshot is kept until it is deleted, so a week of them piles up. Each snapshot stores 2 GB of its own:
- Snapshots kept
- 50 × 20 × 7 days
- 7,000
- Stored
- 7,000 × 2 GB
- 14,000 GB
- Monthly cost
- 14,000 × $0.18 per GB
- $2,520
- Deleted after a day instead of a week
- $360
- Deleted when each task ends
- ≈ nothing
The limit: label each task's snapshots, and delete them with
runtime.snapshots.delete(id) when the task finishes. Give each volume a size you choose, not one
the agent guesses. A volume is charged for its full size from the moment it
exists. A block shared by two of your snapshots counts once, so real snapshot
chains usually cost less than this sum (storage prices).
5. Can an agent run up a bill with network traffic?
Yes, by sending data out. Inbound traffic is free on Runtime. Outbound traffic costs $0.03 per GB from the first GB. An agent that uploads build artifacts in a loop spends it. So does a compromised agent that sends a dataset out.
- Without a limit a paid sandbox moves at most 500 GiB a day, in and out combined. If all of it goes out, beyond the allowance, that costs $16.11 for that one sandbox.
- With limits an
allowOutboundlist in the sandbox's network rules limits traffic to the hosts the task needs, such as your package registry and your model provider. Data cannot leave for any other host, so it cannot be billed either (allow only some hosts).
Which limits can the agent raise by itself?
An agent can change every limit that its own key can reach. Most budget designs
miss this. Network rules can be widened with network.set(). Idle pause can be
turned off with update(). A sandbox's maxCost can be raised with update().
Any key that may run the sandbox can do all of these. A limit the agent can
change is only advice.
| Limit | Stops | Set with | Who can change it |
|---|---|---|---|
| Idle pause | Forgotten sandboxes | idlePauseSeconds at create |
Any key that runs the sandbox |
| Size in your code | Oversized machines | vcpu, memoryGB at create |
Whoever creates |
Command timeoutSeconds |
Hung and looping commands | Each exec |
Whoever runs the command |
Sandbox maxCost |
One runaway sandbox | maxCost at create |
Any key that runs the sandbox |
Network allowOutbound list |
Traffic out, exfiltration | Create or network.set() |
Any key that runs the sandbox |
| Snapshot clean-up | Storage pile-up | snapshots.delete at the end |
Whoever snapshots |
| Account concurrency | Fan-out | Your account | Support, on request |
| Daily spending limit on a key | Everything that key spends | The website, by a person | Only a person; no key, ever |
Two rules follow. First, keep the Runtime key in your orchestrator, the code
that calls the model and runs its tools. Do not put it in the sandbox where the
model's commands run. The model then cannot call update() at all. Second,
give each agent its own key with a spend cap. The cap counts what that key's
sandboxes cost over a rolling window, a day unless you set another. Past the
cap, a create is refused and charges nothing
(set a daily spending limit).
What does the code look like with every limit in place?
Create each task's sandboxes through one function that applies the limits. Check
the task's sandboxes a share of it each. maxCost is the most one sandbox may cost
in all: once it has cost that, it pauses, and it starts again only when you raise
it. This code runs as written:
TypeScriptimport { randomUUID } from "node:crypto";import { Runtime } from "withruntime";const runtime = new Runtime();const TASK_BUDGET = 2.0; // $2 for everything one task startsconst MOST_ATTEMPTS = 4; // each attempt's sandbox gets a quarter of itasync function sandboxFor(task: string, attempt: number) { if (attempt > MOST_ATTEMPTS) throw new Error(`task ${task} has used its ${MOST_ATTEMPTS} attempts`); return runtime.sandboxes.create( { labels: { task }, vcpu: 2, // oversized: the size is yours, never the agent's memoryGB: 4, idlePauseSeconds: 60, // forgotten: pauses a minute after the last use maxCost: (TASK_BUDGET / MOST_ATTEMPTS).toFixed(2), // runaway: it pauses once it has cost this network: { allowOutbound: ["pypi.org", "*.pythonhosted.org"] }, // traffic out }, { idempotencyKey: `${task}-${attempt}` }, // a retried create answers the same sandbox );}const taskId = `task-${randomUUID()}`; // your task's own id, the same on every retryawait using sbx = await sandboxFor(taskId, 1);const run = await sbx.exec("python3 -c 'print(sum(range(10)))'", { timeoutSeconds: 120 });console.log(run.exitCode, run.stdout?.trim(), sbx.info.maxCost);Pythonfrom uuid import uuid4from withruntime import NetworkRules, Runtimeruntime = Runtime()TASK_BUDGET = 2.0 # $2 for everything one task startsMOST_ATTEMPTS = 4 # each attempt's sandbox gets a quarter of itdef sandbox_for(task: str, attempt: int): if attempt > MOST_ATTEMPTS: raise RuntimeError(f"task {task} has used its {MOST_ATTEMPTS} attempts") return runtime.sandboxes.create( labels={"task": task}, vcpu=2, # oversized: the size is yours, never the agent's memory_gb=4, idle_pause_seconds=60, # forgotten: pauses a minute after the last use max_cost=f"{TASK_BUDGET / MOST_ATTEMPTS:.2f}", # runaway: it pauses once it has cost this network=NetworkRules(allow_outbound=["pypi.org", "*.pythonhosted.org"]), # traffic out idempotency_key=f"{task}-{attempt}", # a retried create answers the same sandbox )task_id = f"task-{uuid4()}" # your task's own id, the same on every retrywith sandbox_for(task_id, 1) as sbx: run = sbx.exec("python3 -c 'print(sum(range(10)))'", timeout_seconds=120) print(run.exit_code, (run.stdout or "").strip(), sbx.info.max_cost)Each sandbox's maxCost caps what it can cost, whatever the agent does in it,
and the task starts at most four. So the task never spends more than its
budget, however many times the agent retries.
An agent can also read its key's spend cap before it plans a large fan-out. It can then ask a person, instead of being refused partway through:
TypeScriptimport { Runtime } from "withruntime";const runtime = new Runtime();const usage = await runtime.usage.get();const left = usage.keySpendCap ? Number(usage.keySpendCap.remaining) : Infinity;if (left < 5) console.log("Under $5 left on this key's cap: ask before starting the fan-out.");How do you catch spending you did not plan for?
Watch lifecycle events, not invoices. A webhook on sandbox.paused reports the
moment a sandbox pauses, idle or at its maxCost. A burst of sandbox.created events from one key means a loop is
running. Usage & billing shows what each product cost each day, and how long
your credit lasts at this month's pace. Every owner gets an email when the
balance will last under five days. Credit is prepaid. The balance never goes
below zero, and you never owe more than you added
(metrics and webhooks).
In short
- Forgotten sandboxes are handled by idle pause; keep it on and keep it short.
- Loops, oversized machines and runaway processes need idempotency keys, a
size set in your code, a
maxCoston every sandbox and a timeout on every command. - Storage and traffic out grow quietly; delete each task's snapshots when it ends and narrow the network to the hosts a task needs.
- An agent holding a key can raise most limits. Keep the key in your orchestrator, and give each agent's key a daily limit only a person can change.
Run it on Runtime
Runtime costs 37% to 87% less than fourteen other sandbox providers for an agent that mostly waits on a model (compare costs). Runtime charges $0.03 per vCPU-hour of CPU actually used and $0.008 per GiB-hour of memory, with a plan fee from $25 a month that comes back as usage, and every limit in this post is built in. Start free, with a 7-day Pro trial with $5 of usage at withruntime.com, and set the daily spending limit on your first key before an agent ever uses it.