EXAMPLE 04
  • caches
  • performance

Shared package caches

New sandboxes stop downloading the same packages again.


The problem

Throwaway instances are only cheap if they start fast. Each new container begins with an empty package cache, so every npm install or cargo build downloads the same dependencies again, once per instance, per rebuild.

caches fixes that with one line: each named cache is one directory in the config dir’s shared-volumes/, mounted into every sandbox that lists it.

Let your agent set this up

Config

devsandboxes.toml
[template.base]
image = "node:22"
caches = ["npm"]            # one npm cache for every sandbox and instance

[sandbox.web]
extends = "base"
folder = "../web"
postCreateCommand = "npm install"

[sandbox.api]
extends = "base"
folder = "../api"
postCreateCommand = "npm install"

Try it

From the config dir:

TERMINAL
devsandbox run web                     # npm install fills shared-volumes/npm
devsandbox run web --name fix-login    # same install, served from the cache
devsandbox run api                     # the api shares it too
devsandbox exec web sh -c 'echo $npm_config_cache'   # /root/.npm
  • --name: the instance name.

How it works

  • Valid names are pnpm, cargo, npm, yarn, go and pip; each sets the tool’s env vars to its mount (caches).
  • Arrays concatenate under extends: a sandbox can add its own, e.g. caches = ["cargo"] (templates).
  • rm and gc leave caches alone; delete a directory in shared-volumes/ to start that cache over.
  • Mounts target /root/…, so the sandbox must run as root (node:22 does).

Agent instructions

Prompt for your coding agentPaste into Claude Code, Codex or any agent with a shell.

Share package caches across my devsandbox sandboxes so new instances stop re-downloading dependencies.

  1. Read the devsandbox-cli and config-toml-spec skills first (load them if they are installed, otherwise read them from https://github.com/Nemikolh/devsandboxes/tree/main/skills). Follow them over your own assumptions: unknown config keys are hard errors.
  2. Find my devsandbox config dir: the folder holding devsandboxes.toml, passed to devsandbox as -C <config dir>. If you cannot tell which one, ask me.
  3. Find which package managers my sandboxes use and add them to caches (valid: pnpm, cargo, npm, yarn, go, pip), in a template every sandbox extends if there is one.
  4. The caches mount under /root, so check each sandbox runs as root. Tell me about any that does not rather than changing its user.
  5. Validate with devsandbox -C <config dir> ls and fix every error it reports before going on.
  6. Existing instances now drift: list them with devsandbox -C <config dir> ps -a and ask me before running devsandbox -C <config dir> rebuild <instance> on each.
  7. Check devsandbox -C <config dir> exec <instance> env shows the cache variables (e.g. npm_config_cache), and that <config dir>/shared-volumes/ fills up after an install.
  8. Ask me before anything destructive: devsandbox rm, gc, rebuild --force, service rebuild, deleting files or branches.
fill in before sending Agent skills (opens in a new tab)

Source: site/src/content/examples/caches.mdxEdit this page on GitHub(opens in a new tab)

MENU /
View on GitHub
EXAMPLES
All examplesEvery recipe on one page.Parallel coding agentsSeveral coding agents on one repo, fully isolated from one another.One shared PostgresOne development database for all your sandboxes and their instances.Private services per instanceEvery instance gets its own Postgres and Redis, so agents never touch each other's data.Shared package cachesNew sandboxes stop downloading the same packages again.ssh-agent and git pushAgents push over ssh with your host's keys, which never enter the container.Port forwarding on demandOpen a sandbox's dev server or database from your host, without restarting anything.Attach VS CodeOpen any instance in VS Code with one key.devcontainer FeaturesAdd Node, Rust or the GitHub CLI to any image, in TOML.Babysit pull requestsAn agent keeps your open PRs merged with their base, and pings you when it can't.Port a devcontainer.jsonTurn an existing devcontainer.json into a devsandbox config.