unContainer

Guides

Share dependency downloads across worktrees

Download packages once in a networked worktree, then install them offline in every other worktree of the same project. Installed dependencies stay private to each guest.

Define an online and an offline profile

Create uncontainer.json at the worktree root. Each caches entry names a directory under the guest’s /home/user/.cache.

uncontainer.json{ "cacheMaxSize": "512MiB", "profiles": { "deps": { "cpus": 2, "caches": ["uv"], "allow": ["pypi.org:443", "files.pythonhosted.org:443"] }, "test": { "cpus": 2, "memory": "512MiB", "network": "none", "caches": ["uv"] } } }

Check what the CLI sees:

uncontainer profile list --json

Warm the cache once

With uv and a compatible Python available in the guest, sync from PyPI in the first worktree:

uncontainer run --profile deps -- uv sync --locked

Install offline everywhere else

In a second worktree with the same lockfile, the network stays off:

uncontainer session open --profile test uncontainer session exec -- uv sync --locked --offline

Each guest builds its own .venv. An offline sync works only if every needed package was cached by an earlier online run.

npm and Cargo

Set "caches": ["npm", "cargo"] in both profiles and allow HTTPS to registry.npmjs.org, index.crates.io and static.crates.io in the online one. Run these inside the respective sessions:

Online worktreeOffline worktree
npmnpm ci --cache ~/.cache/npmnpm ci --offline --cache ~/.cache/npm
CargoCARGO_HOME=~/.cache/cargo cargo build --lockedCARGO_HOME=~/.cache/cargo cargo build --locked --offline

Each guest creates its own node_modules and target. Keep registry credentials outside the shared Cargo home.

How sharing works

  • The host keeps one compressed snapshot per cache name, Git repository, guest distro and architecture.
  • A guest refreshes its private copy before each foreground command and archives it after successful commands.
  • If two guests update the same snapshot at once, the first publication wins. Use these directories for disposable downloads only.
  • Large caches add time to each command. Budget them with cacheMaxSize, described in Where data lives.

Start over

uncontainer cache clean

Removes the saved caches for every profile and distro of the project. To rebuild offline afterwards, warm the cache again from a networked guest.