Engineering

Sandboxes that boot in 300 ms

Every Nest project runs in its own isolated sandbox. Here is how we got boot times down to about 300 ms, and why that speed matters for the agent.

Theo MarchettiCo-founder and CTO

A row of server blades lit in blue in a data center rack
Photo: panumas nikhomkhai / Pexels

Every Nest project runs in its own sandbox: an isolated machine with its own file system, its own Node process and its own Postgres database. When you open a project, edit code or preview a change, that sandbox has to be running. For a long time, starting one took several seconds. Today the typical sandbox boots in about 300 milliseconds.

This post explains how we got there and why we cared so much.

Why boot time matters

For a person, a three-second wait to open a project is mildly annoying. For the agent we are building, it is a much bigger deal.

When the agent verifies a change, it boots the app, runs the type checker, applies migrations to a fresh database and opens the result in a headless browser. If a check fails, it fixes the code and does it all again. A single request can involve a dozen of these cycles. At several seconds per boot, the waiting adds up to minutes, and the agent spends more time idle than thinking.

Fast sandboxes also change behavior. When testing is cheap, the agent tests more often, in smaller steps, and catches mistakes earlier. Speed turned out to be a reliability feature.

Where the time went

When we first profiled a cold boot, the time broke down roughly like this:

  • Starting the machine: creating the isolated VM and its network.
  • Installing dependencies: resolving and linking a project’s packages.
  • Starting Postgres: initializing a database and running migrations.
  • Starting the dev server: compiling the app for the first request.

Each needed a different fix.

What we changed

Snapshots instead of cold starts

The biggest win came from not booting at all. After a sandbox reaches a ready state, with the dev server running and Postgres accepting connections, we take a memory and disk snapshot. The next time that project is needed, we restore the snapshot instead of starting from scratch. Restoring a snapshot is mostly a matter of mapping memory pages, and pages are loaded lazily as the process touches them.

Snapshots are taken per project and refreshed whenever dependencies or the schema change, so a restored sandbox always matches the current code.

Warm pools

Snapshots help with projects we have seen before. For new projects and new templates, we keep a pool of pre-booted sandboxes in each region, already running a base image with Node, Postgres and our tooling loaded. Claiming one is a matter of assigning it to a project and copying in the files. We size the pools from recent traffic, so they grow during busy hours and shrink overnight.

Dependency caching

Most Nest apps share a large set of dependencies. We keep a content-addressed cache of packages on each host, and sandboxes link to it read-only instead of downloading anything. A fresh install for a typical project went from several seconds to a few hundred milliseconds, and for projects restored from a snapshot it disappears entirely.

Database branching

Instead of initializing Postgres and replaying every migration, each sandbox starts from a copy-on-write branch of the project’s database at its latest schema. When the agent tests a new migration, it runs on a throwaway branch, so a failed migration costs nothing and leaves your data untouched.

The numbers

Here are boot times measured across all projects over a week, before the work started and after the last piece shipped.

Boot type p50 before p95 before p50 after p95 after
Existing project 3.8 s 9.2 s 0.31 s 0.74 s
New project from template 6.1 s 14.5 s 0.42 s 1.1 s
Agent test cycle 4.4 s 10.8 s 0.28 s 0.66 s

The p95 numbers are the ones we watch most closely. A fast median with a slow tail still feels unreliable, because the slow cases are the ones people remember.

What is next

Isolation stays non-negotiable through all of this. Each sandbox is a separate VM with no shared memory or file system with other projects, and the dependency cache is read-only. Nothing we did for speed weakens that boundary.

Next, we are working on making snapshots portable across regions, which will matter when we open new data regions, and on bringing the slowest p95 cases under half a second. The agent’s test loop is already noticeably tighter, and we expect that to show up as fewer errors in its hand-backs.

#infrastructure#performance
Portrait of Theo Marchetti

Written by

Theo Marchetti

Co-founder and CTO

Python code in a dark editor theme, close up on a screen

Engineering

How Nest checks its own work

Type checks, generated tests, a headless browser, screenshot diffs and a retry budget. A look at how Agent mode verifies a change, and where it still falls short.

Streaks of purple and green light curving through a dark frame

Product

Introducing Agent mode

Nest can now plan a change, make it across your whole project, test it in a real browser and fix what breaks before handing the app back to you.

A team cheering around laptops at a meeting table in a bright office

Company

Our $48M Series B

Nest has raised a $48M Series B led by Harbourline Ventures. Here is where we are, what the money is for and what stays the same.

Type to search every post.