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.
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,goandpip; 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). rmandgcleave caches alone; delete a directory inshared-volumes/to start that cache over.- Mounts target
/root/…, so the sandbox must run as root (node:22does).
Agent instructions
Share package caches across my devsandbox sandboxes so new instances stop re-downloading dependencies.
- 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.
- 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. - Find which package managers my sandboxes use and add them to
caches(valid: pnpm, cargo, npm, yarn, go, pip), in a template every sandboxextendsif there is one. - The caches mount under /root, so check each sandbox runs as root. Tell me about any that does not rather than changing its user.
- Validate with
devsandbox -C <config dir> lsand fix every error it reports before going on. - Existing instances now drift: list them with
devsandbox -C <config dir> ps -aand ask me before runningdevsandbox -C <config dir> rebuild <instance>on each. - Check
devsandbox -C <config dir> exec <instance> envshows the cache variables (e.g. npm_config_cache), and that <config dir>/shared-volumes/ fills up after an install. - 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)