Skip to content

Sandboxes

By default an agent’s commands run on your computer, as you. A sandbox thread’s commands run in a small virtual machine of the thread’s own, with Docker inside it. The thread’s folder is shared into the VM, so files are the same on both sides and nothing is copied.

Sandboxes are experimental. Turn them on in Settings → Experimental. They need macOS 15 or later on Apple silicon, or Linux with KVM.

  • An agent running rm -rf or a rogue install script can damage only the VM and the thread’s own folder.
  • You can limit which hosts the VM can reach.
  • Secrets can be used by commands in the VM without the commands being able to read them.
  • Each thread has its own Docker, so two threads’ docker compose up don’t collide.

With sandboxes enabled, New thread has a Sandbox switch next to Worktree | Local. To make it the default for a project, turn on Run new threads in a sandbox on the project’s page in Settings.

A thread that an agent in a sandbox starts gets a sandbox too. A fork of a sandbox thread gets a new sandbox of its own unless you uncheck Keep it in a sandbox in the Fork dialog.

Use Worktree with Sandbox. A Local sandbox shares your whole checkout with the VM, including .git. On macOS endurable locks the checkout’s git hooks and config while the VM runs, so code in the VM can’t plant something that later runs on your computer. This also means your own git config and hook installers fail in that checkout until the sandbox stops. On Linux there is no such lock, and code in the VM can write them. A Worktree sandbox avoids all of this: the VM can’t write to your repository’s config, hooks, or other branches.

A project that runs its own extensions can’t have a Local sandbox at all. Those extensions run on your computer from the checkout, and code in the VM could rewrite them. Use Worktree, or turn the project’s extensions off.

flowchart LR
  subgraph computer [Your computer]
    folder[(The thread's folder)]
    keychain[(Keychain)]
  end
  subgraph vm [The thread's microVM]
    cmds[Commands, terminals,<br/>Docker, dev servers]
  end
  cmds <-- "shared, at the same path" --> folder
  cmds -- "allowed hosts only" --> net([Internet])
  keychain -. "a secret is swapped in on the way out,<br/>for its own hosts only" .-> net

The agent’s shell commands, terminals, setup and teardown scripts, and the servers Preview shows all run in the VM. To reach one of those servers from your own tools, such as a database from psql, forward its port.

The agent’s file tools (read, write, edit, search) run on your computer but are held to the thread’s folder. They can’t follow a link out of it and can’t write anything under .git.

Anything else that would act outside the VM asks you first, in every permission mode:

  • a tool from an extension or MCP server, since those run on your computer. Always on the approval lets that one tool through from then on.
  • a message to a thread that isn’t sandboxed,
  • reading a thread outside its own family of threads,
  • when the project has an allowlist, a web search, or a fetch from a host that isn’t on it.

A sandboxed agent’s search of your other threads covers only its own family, too.

A new sandbox starts in about a quarter of a second, with Docker already running. It’s restored from a snapshot, called a template, that endurable builds ahead of time for each project.

Building a template runs, in order:

  1. .agents/template.sh, if the project has one. Put here what only the VM needs: a language toolchain, system packages. It runs once, as root, and never on your computer.
  2. .agents/setup.sh, so packages are installed, images pulled and containers started before any thread exists.

Both are read from the committed files on the project’s base branch, never from your working copy, so a template never contains your .env.

Templates rebuild in the background when those scripts change, and weekly. Only a project’s very first sandbox waits for a build, and Build sandbox on the project’s page in Settings builds it ahead so that one doesn’t either. The page shows the template’s state, and the button becomes Rebuild sandbox.

The setup script is run ahead only if it can safely run a second time over its own work, since each thread runs it again when its sandbox restarts. If it can’t, the template is built without it, each new thread runs it from the start, and the project’s page says so.

If a script depends on other files, say so in a comment and the template rebuilds when they change:

Terminal window
# inputs: package-lock.json docker/

A sandbox can reach the public internet. It can’t reach your computer or your local network.

Each project has an Allowed hosts list on its page in Settings, one host per line. With hosts listed, the project’s sandboxes can reach only those hosts. *.github.com covers github.com and every name under it.

A new project starts with a list worked out from its files: GitHub, plus the registries its package managers use. Add the usual hosts works that out again from the project as it is now and adds whatever is missing. It never removes a host. Leave the list empty and sandboxes reach any host.

A host that isn’t on the list doesn’t resolve inside the sandbox, so a blocked command fails with a DNS error such as “Could not resolve host”, not with a message about the list. Building a template isn’t held to the list, so template.sh and setup.sh can install from anywhere.

A change to the list applies to sandboxes made afterward. For an existing thread, use Refresh sandbox.

A secret used by a sandboxed command never enters the VM. The command gets a placeholder. The real value is swapped in as the request leaves the VM, and only if the request is going to one of the hosts that secret is allowed to be sent to.

  • A secret with no hosts listed is sent nowhere from a sandbox.
  • If a command tries to send a secret to a host that isn’t on its list, the request is refused, and you’re asked afterward whether to allow that host.
  • The first time a command in a sandbox uses a secret, the VM restarts once to take secrets. Whatever was running in it stops, and the command’s output says so. The project’s later sandboxes start ready.
  • This works for a token sent in a request header. It can’t work for a database password, or a key used to sign requests. For those, a secret has a Give sandboxes the value itself switch. Code in the VM can then read the value, so only the network allowlist protects it.

An unused sandbox costs memory, so endurable pauses it after 15 minutes and stops it after 30. Both are settings in Settings → Idle & snooze, and either can be Never. A terminal or Preview left open doesn’t count as use.

  • Paused: frozen in place. The next use resumes it instantly, with its servers and containers as they were.
  • Stopped: memory is released and files are kept. The next command starts it again in a second or so and reruns the setup script, if the template ran it. Other processes that were running are gone.

The thread’s header shows “Sandbox · paused” or “Sandbox · stopped”. While the agent isn’t working, the ⋯ menu has whichever of Pause sandbox, Stop sandbox, Resume sandbox and Start sandbox fits its state. ⌘K has Pause all sandboxes and Stop all sandboxes, which leave alone the ones agents are working in.

Refresh sandbox throws the VM away and makes a new one from the project’s current template. The thread’s files stay. Use it to pick up a new template or a changed allowlist. It waits for the agent’s turn to end.

Archiving a thread stops its sandbox. Deleting or shipping it removes the sandbox.

A sandbox is a real boundary for commands, which the rest of endurable’s guards are not. It still isn’t a place for code you consider hostile:

  • The VM can write the thread’s folder, and you’ll probably run what it wrote.
  • A host on the allowlist that serves anyone’s content, GitHub above all, can still be sent whatever the thread has read.
  • A thread in a sandbox can’t be moved to another machine.