Most agent sandboxes are oversized. Teams pick a big box once, because a build failed on a small one, and every run after that pays for it. Others go small and lose runs to out-of-memory kills that the model then tries to "fix" by rewriting code that was fine. Sizing is worth ten minutes of thought per workload. This is a reference for doing it, with Sandscale's limits where they apply.
What drives each resource
vCPUs matter when the work is parallel: compilers (make -j, cargo build), test runners with workers, npm ci resolving many packages. A single Python script that runs pandas on one core gets nothing from a second vCPU. Most model-written snippets are single-threaded.
Memory is what kills runs. Data loaded into a dataframe, a language server, a bundler holding a module graph, a test suite starting a database: each can be the reason a box needs more. When a process exceeds the memory the box has, it is killed, and the exit looks like a crash.
Disk matters for dependency trees, Docker-in-sandbox, datasets and build artifacts. node_modules for a mid-sized web app and a Python environment with scientific packages both take real space.
Measure, then pick
Run the workload a few times on a generous box and record peaks, not averages:
/usr/bin/time -v python analysis.py 2>&1 | grep -E 'Maximum resident|Elapsed' du -sh /workspace nproc /usr/bin/time -v reports maximum resident set size, the peak memory of the process. If it is not in your template, read /sys/fs/cgroup/memory.peak where the kernel exposes it, or sample free -m during the run. Then size to the peak plus a margin (a quarter to a half more is a common rule of thumb), and pick vCPUs from whether the work is parallel.
Reading the result when a box is too small
On Sandscale, sandboxes.run() returns flags that tell you why a command ended, instead of leaving the model to guess:
const result = await sandscale.sandboxes.run(box.id, ['pytest', '-q'], { region: box.region, timeoutSeconds: 300, }); if (result.oomKilled) { // out of memory: tell the model plainly, and consider a larger size for this workload } else if (result.timedOut) { // hit the command limit: a loop, a hang, or a box too small for the work } Pass these to the model as facts ("the command was killed because it ran out of memory") rather than raw output. A model told that its process was OOM-killed will reduce batch sizes or stream data; a model shown only Killed often rewrites unrelated code. Our post on designing a run_code tool schema shows a result shape that carries this through.
Sandscale's limits and how memory counts
| Free | Pro | Team | Enterprise | |
|---|---|---|---|---|
| vCPU per box | Up to 2 | Up to 16 | Up to 16, 32 on request | Up to 64 |
| Boxes at once | 3 | 30 | 30, more on request | Custom |
| Memory included | 4 GiB per vCPU | 4 GiB per vCPU | 4 GiB per vCPU | 4 GiB per vCPU |
| Burst | No | Up to 4x the base size | Up to 8x the base size | Custom |
| Included storage | 5 GB | 50 GB | 100 GB per member, pooled | Custom |
Source: plans and limits and pricing.
Memory above 4 GiB per vCPU counts as vCPU-hours: every 4 GiB-hours of extra memory is one vCPU-hour. So a 2 vCPU box with 8 GiB costs the same per awake hour as 2 vCPU-hours; the same box with 16 GiB costs 2 for the vCPUs plus 2 for the extra 8 GiB. The pricing page adds that "every box gets exactly the vCPUs and memory you picked, plus any burst you set, never more".
Set size on create:
const box = await sandscale.sandboxes.create({ template: 'builtin:python', cpuCount: 2, memoryMb: 8192, }); If you start from a template that has a size, nonzero values you pass must match it; the server checks.
A starting table
These are starting points to measure against, not measurements of ours.
| Workload | Start with | Raise when |
|---|---|---|
| Model-written snippets, small scripts | 1 vCPU, default memory | oomKilled on data loads |
| Data analysis on CSVs up to a few hundred MB | 1 to 2 vCPU, 8 GiB | Peak RSS approaches the limit |
| Unit tests for a typical web app | 2 vCPU | Test runner uses workers and wall time matters |
| Full builds (Rust, large TypeScript, C++) | 4 to 8 vCPU | Compiler parallelism is the bottleneck |
| Agent with a language server and dev server | 2 to 4 vCPU, 8 to 16 GiB | Both servers plus tests exceed memory |
Size per workload, not per platform
Keep a small map in code from workload type to size, and let the agent choose the workload type, not the numbers:
const SIZES = { snippet: { cpuCount: 1 }, analysis: { cpuCount: 2, memoryMb: 8192 }, build: { cpuCount: 8 }, } as const; That keeps the model from asking for 16 vCPUs "to be safe", gives you one place to change sizes after you measure, and makes runs comparable in your logs. Record the size on each run's labels so the next sizing review has data.
Originally published on the Sandscale blog.
