Skip to content

feat(sandbox): install Incus sessions through the node's registry caches - #5017

Merged
yannickmonney merged 21 commits into
mainfrom
feat/sandbox-registry-caches
Oct 19, 2026
Merged

yannickmonney merged 21 commits into
mainfrom
feat/sandbox-registry-caches

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An Incus sandbox node can run package registry caches (an npm cache and a PyPI index on a network of their own). Today every session installs from the public registries through the egress proxy, so a node with many sessions downloads the same packages again and again and the caches serve none of them. This adds two optional spawner settings that point sessions at the caches, and an optional deny-list on the egress proxy so that a package manager that ignores its configuration fails visibly instead of installing around the cache. Everything is off unless set: a deployment that sets none of the three variables gets the same instance, environment, home and proxy configuration as before.

The Incus backend only. The Docker and Kubernetes backends and the nested Docker daemon are untouched.

What changes

Setting Read by Meaning
SANDBOX_INCUS_NPM_REGISTRY spawner npm cache: an http:// URL whose host is an IPv4 address
SANDBOX_INCUS_PYPI_INDEX spawner PyPI simple index, same form; its host and port are what pip is told to trust and uv to allow, so there is no third setting to keep in step
SANDBOX_EGRESS_DENIED_HOSTS egress proxy host names the proxy refuses while everything else stays open
  • Boot validation. Both URLs must be http: with an IPv4 literal host (the same grammar SANDBOX_EGRESS_PROXY is held to, through isIpv4Address): a session's bridge resolver forwards nothing, so a session is given address literals, never names. Boot refuses a name, https:, credentials, a query, a fragment, and any character that an .npmrc, an ini file, a TOML string and a shell word would not all read the same. incus-registry-caches.ts is pure and holds the settings, the host list and the rendering of the instance variables.
  • What a session gets. The spawner puts TALE_REGISTRY_CACHE_NPM / TALE_REGISTRY_CACHE_PYPI in the instance's environment (an address is no secret) and adds the cache addresses to NO_PROXY, because the egress proxy refuses private destinations. The runtime entrypoint then writes, before runnerd starts and at every start (resume included), ~/.npmrc, ~/.bunfig.toml, ~/.config/pip/pip.conf and ~/.config/uv/uv.toml. The first line of each file says the sandbox wrote it: such a file is rewritten when the cache moves and removed when its setting is gone; a file without that line is the session's own and is never replaced or removed; a symbolic link in its place is not followed. A failed write is a warning, not the end of the boot. The warm pool's fingerprint moves with the settings, so a standby made before is replaced.
  • Egress deny-list. SANDBOX_EGRESS_DENIED_HOSTS makes tinyproxy answer 403 for a listed host and its subdomains, and the proxy's DNS forwarder answer NXDOMAIN for them. The documented value is registry.npmjs.org,registry.yarnpkg.com,pypi.org,files.pythonhosted.org; REGISTRY_HOSTS in the spawner is the one list, boot prints the value for the caches that are set, and a test holds the docs, .env.example and the egress template's comment to it. The proxy refuses to start on an entry that is not a plain host name, on a list that names no host, and beside SANDBOX_EGRESS_ALLOWLIST. Browsing stays open: only the listed hosts leave the path.
  • Locked installs. npm ci and bun install (a lock that records no registry) go through the cache. A pip requirements file locked by hash installs from the index. A uv.lock records the address of every file it was made against, so uv sync goes around the index and meets the proxy's refusal; the docs show the supported path (uv export --frozen then uv pip install --require-hashes). No lock file is rewritten.
  • What the caches are. One set of caches serves every organization the node holds. They are read-only, hold public packages only, and nothing private goes through them: the files carry no credential and a session's own .npmrc or pip.conf stays. The docs say plainly that the caches show which public packages were fetched (Verdaccio lists them) and what the deny-list takes away (a page on pypi.org, a private package held on registry.npmjs.org).
  • Docs. services/sandbox/docs/incus.md (settings table, a "Package registry caches" section, the capability row and the "Not supported" line, a verify step), .env.example, services/sandbox-egress/README.md, services/sandbox/README.md, and docs/{en,de,fr}/self-hosted/ (configuration/environment-reference.md, operate/security/hardening.md, operate/observability/troubleshooting.md). No UI string, so no message catalog changes.
  • Lab. One case in the Incus lab's network suite (services/sandbox/e2e/incus/suites/network.e2e.ts) with stand-in npm and PyPI servers (registry-stand-ins.ts, with its own offline tests): a session with the settings installs a locked npm project, a pip project locked by hash and the same requirements through uv from them, and reaches no registry host (a tunnel to each answers 403, the name NXDOMAIN) while another host stays open. jszip (devDependency of @tale/sandbox, pinned) builds the stand-ins' archives.
  • Turbo inputs. services/sandbox/turbo.json and tools/cli/turbo.json list the new files the suites read (the runtime entrypoint, the egress README, .env.example, the three environment references, incus-registry-caches.ts), and the CLI's spawner-configuration test helper lists the new module.

Dormancy

With none of the three variables set: the instance's environment has no TALE_REGISTRY_CACHE_* and an unchanged NO_PROXY; the pool fingerprint is the old one; the runtime entrypoint writes and removes nothing (it removes only a file that carries its own marker line); the egress proxy renders the configuration it rendered before. Tests hold each of these (incus-session-spec.test.ts, incus-config.test.ts, registry-cache-files.test.ts, egress-proxy-config.test.ts). An older runtime image with a newer spawner writes no files; the docs say to roll the image and the spawner together and to set the proxy's list last.

Checklist

  • bun run check passes (format, lint:conflicts, lint:links, turbo run lint typecheck test test:ui), 49 of 49 turbo tasks, on the branch tip, which is on origin/main d643fd5924 with no rebase needed. The first two whole runs each failed one 5-second exec timing test of @tale/sandbox-runtime-daemon while the Mac was at load 30 (ExecManager > a cancelled exec ends its background processes too, then an exec's environment > a command printing its environment never sees the token; neither touches this diff); the package passes alone (618 pass, 21 skip, 0 fail) and the whole gate passes with --concurrency=2. See the test plan.
  • The same gate on this branch stacked on origin/main 8693945855 (one commit past the base above, no conflict; stacked locally, the branch is not rebased): bun run check --concurrency=2, 49 of 49 turbo tasks, exit 0 (@tale/sandbox 2233 pass, @tale/sandbox-runtime-daemon 618 pass, @tale/cli 3829 pass, 0 fail in each).
  • bun run lint:sast passes (Opengrep): 476 rules on 5890 files, 0 findings.
  • Translations: N/A for message catalogs (no key added). The user docs are updated in docs/{en,de,fr}/.
  • Docs updated in docs/{en,de,fr}/.
  • README.md / README.de.md / README.fr.md: N/A, no root README change (services/sandbox/README.md and services/sandbox-egress/README.md are updated).

Test plan

Local, bun 1.4.2, NODE_OPTIONS=--max-old-space-size=6144 for the type check:

  • bun run check over 49 turbo tasks, green on the last run: @tale/sandbox 2233 pass, 1 skip, 0 fail; @tale/sandbox-runtime-daemon 618 pass, 21 skip, 0 fail; @tale/cli 3731 pass, 35 skip, 0 fail; @tale/platform test 1488 files passed (2 skipped); test:ui 778 files passed; @tale/docs 38 files passed. 44 of the 49 tasks replayed from the shared Turbo cache that an earlier run of the same inputs filled; the sandbox, daemon, platform and CLI test tasks executed on that last run.
  • New and changed suites: the registry settings and their refusals (incus-registry-caches.test.ts, incus-config.test.ts, config-incus.test.ts), the session spec (incus-session-spec.test.ts: default byte-identical, set adds the variables and NO_PROXY, the fingerprint moves), the entrypoint's files byte for byte, marker rules, removal, a foreign file and a link left alone (registry-cache-files.test.ts, which drives the real entrypoint), the proxy's rendering and refusals (egress-proxy-config.test.ts), and a contract test that holds the documented host list, .env.example, the three environment references and the egress template to the setting (incus-registry-caches-contract.test.ts).
  • bun run lint:sast 0 findings; bunx knip exit 0; commitlint over every commit of the branch passes.
  • By hand on a Mac, with throwaway containers removed afterwards: real tinyproxy and dnsmasq in an Alpine container refuse a listed host with 403 on CONNECT and plain HTTP and with NXDOMAIN for it and its subdomains while another host reaches the internet; real npm ci, pip install --require-hashes, uv pip install --require-hashes and bun install install from the lab's stand-in caches using the files the real entrypoint wrote (dash and bash); uv sync from a uv.lock goes around the configured index, as documented.

Not run, and not claimed:

  • The Incus lab case itself: it needs the Incus lab on a hosted runner. It is type-checked, and its stand-ins have their own offline tests.
  • The merge queue's jobs (E2E, Build, CLI, UI, Browser, backend integration) and the Windows CLI job, which run in the queue only.
  • A real Verdaccio and devpi behind the ACL of a real node, and a session's own file surviving a stop and a resume on Incus (the entrypoint test runs it again over a home that already holds the file).

Ops follow-up

Nothing here is used until an environment sets the variables. After a release carries it, the ops repository sets SANDBOX_INCUS_NPM_REGISTRY and SANDBOX_INCUS_PYPI_INDEX in the sandbox environment each platform declares, reading the cache addresses from the node's own cache declaration rather than restating them; adds an ACL rule for each cache's port to the sandbox zone; rolls the runtime image and the spawner together; and sets SANDBOX_EGRESS_DENIED_HOSTS on the egress proxy last (recreate it to apply).

SANDBOX_INCUS_NPM_REGISTRY and SANDBOX_INCUS_PYPI_INDEX name the npm and
PyPI caches an Incus session may install through. Both are optional and
off by default. Boot refuses a value that is not an http URL whose host is
an IPv4 literal (a session resolves no name before it reaches a cache) or
that carries a character an .npmrc, ini file, TOML string or shell word
would read differently. The PyPI trusted host is the index URL's own
host and port, so the two cannot disagree.

Boot logs which caches are set and which registry hosts the egress proxy
should then refuse.

The CLI's cross-check of the spawner's configuration modules and its
test inputs name the new module.
With SANDBOX_INCUS_NPM_REGISTRY or SANDBOX_INCUS_PYPI_INDEX set, every
instance and every warm standby carries the cache addresses in its
environment (TALE_REGISTRY_CACHE_NPM and TALE_REGISTRY_CACHE_PYPI) and
the cache hosts join NO_PROXY, because the egress proxy refuses private
destinations. A standby made under other settings no longer matches the
pool fingerprint and is replaced.

With neither variable set the environment is byte for byte what it was.
The runtime entrypoint reads TALE_REGISTRY_CACHE_NPM and
TALE_REGISTRY_CACHE_PYPI and, before runnerd starts, writes ~/.npmrc,
~/.bunfig.toml, ~/.config/pip/pip.conf and ~/.config/uv/uv.toml as the
session user. pip trusts the index host and uv allows it, because a cache
answers plain HTTP.

Every start settles the files again: one the sandbox wrote (its first line
is a marker) is rewritten, or removed once its cache is no longer named,
so a resumed workspace never keeps the address of a cache that was
switched off. A file without the marker is the owner's own and is never
touched. A symbolic link is never followed: one that points at a file the
sandbox wrote is replaced by a file, and any other is left alone. A value
that is not a plain http URL, or a file that cannot be written, is a
warning and never stops the boot.

With neither variable set nothing is written or said.
SANDBOX_EGRESS_DENIED_HOSTS keeps egress open and refuses the host names
it lists, each with its subdomains: tinyproxy answers a request or a
CONNECT for one with 403, and the DNS forwarder answers it NXDOMAIN, so a
client that resolves through the proxy and then connects by address fails
at the name. A deployment whose sessions install through package caches
lists the public registries, so that a package manager that ignores its
configuration fails visibly instead of installing around the cache.

Entries are plain host names with a domain, never regular expressions. The
entrypoint stops the start on anything else, on a list that names no host,
and when SANDBOX_EGRESS_ALLOWLIST is also set. Unset, the proxy renders
exactly the config it did before.
A case of the Incus lab's network suite gives the spawner two stand-in
caches on the gateway's address, one npm and one PyPI, each serving a
package that exists nowhere else, adds an ACL rule for each port and
gives the egress proxy the four registry hosts to refuse. A session then
has the package manager files and the NO_PROXY entry, installs a locked
npm project, a pip project locked by hash and the same requirements
through uv from the stand-ins, and reaches no registry host: the proxy
answers a tunnel to each 403 and its resolver NXDOMAIN, an npm told to use
the public registry fails, and the rest of the web stays open. The case
puts the ACL rules and the proxy back as it found them.

The stand-ins make their packages themselves, and an offline test holds
the archives, the lock files and the servers' answers in shape.
The Incus contract gets a section on the two cache settings and the
egress proxy's list: what boot accepts, the ACL rule each cache needs, the
files a session is given and when they are rewritten, replaced or left
alone, how locked npm, bun, pip and uv installs go through the caches, and
that the caches are shared by every organization, read-only and public
only. The environment reference (English, German, French) lists
SANDBOX_INCUS_NPM_REGISTRY, SANDBOX_INCUS_PYPI_INDEX and
SANDBOX_EGRESS_DENIED_HOSTS, the hardening guide says where the deny-list
fits beside the allow-list, and the verify-a-node list names what to check.
One list names the public registries the caches replace. A test holds the
value the contract and each language of the environment reference give
the egress proxy to it, the settings and variables those pages name to
the code that reads them, and the variables the entrypoint reads to the
ones the spawner sets. The proxy's own tests take their hosts from the
same list. The spawner's test inputs name the files the new test reads
outside its workspace.
tinyproxy matches the host of a request or a CONNECT as the client wrote
it, and the proxy resolves that name itself. A deny-list entry for
registry.npmjs.org therefore let registry.npmjs.org. through, a name that
resolves to the same address and that the DNS forwarder's refusal never
sees on this path. Each pattern now takes one trailing dot.

Against tinyproxy 1.11.3 a CONNECT to the dotted name was tunnelled with
the old pattern and answered 403 with the new one. The unit test matches
the dotted forms, and the lab case tunnels to each registry host in both
forms.
The template, the entrypoint and the firewall script described two
egress modes, open and allow-list. SANDBOX_EGRESS_DENIED_HOSTS makes a
third, open egress that refuses named hosts, so each comment now says
which mode renders which filter and that the SSRF firewall applies in
every one of them.
SANDBOX_EGRESS_DENIED_HOSTS reaches the container through the compose
env_file, which docker compose restart does not read again, so a restart
left the old list in force. The README now says to recreate the service,
as the environment reference does.
SANDBOX_INCUS_NPM_REGISTRY and SANDBOX_INCUS_PYPI_INDEX join the Incus
block and SANDBOX_EGRESS_DENIED_HOSTS joins the sandbox-egress settings,
each commented out as its neighbours are. The entries say what each
value is, that the ACL and the proxy's list go with them, that the
egress proxy reads its list and must be recreated, and that the list and
SANDBOX_EGRESS_ALLOWLIST exclude each other.
An image from before the cache settings writes no package manager files,
so its sessions install from the public registries, which is harmless
until the egress proxy refuses those hosts: then every install fails.
The Incus contract said such a session installs as before, and the
environment reference only asked for an image of the spawner's release.
Both now say that the image and the spawner roll together and that the
proxy's list is set last, in English, German and French.
The Incus contract said the egress proxy refuses to start on an empty
list. The entrypoint treats an empty SANDBOX_EGRESS_DENIED_HOSTS, what a
templated ${VAR:-} yields, as unset and starts with every registry open.
Only a value that names no host, such as a comma or a space, stops the
start.
Verdaccio answers GET /-/all with every package it has fetched, with its
web interface off as on the node, so a session can list the public npm
packages that sessions of other organizations installed, though not
which organization installed them. devpi's index lists the whole
upstream and not what was fetched. The contract said only that the
operator of the caches sees it.

Docker inside a session reaches the internet through the same egress
proxy and resolves through the same forwarder, so with the proxy's list
set a nested npm or pip install cannot reach the four registry hosts
either, and the nested builder has no cache to fall back to. The
contract implied those builds still reached the public registries.
write_registry_cache_files takes the home as its first argument, and its
caller passes the literal /agent/.runtime/home. The tests do not pass a
home. They run the whole entrypoint with /agent moved under a temporary
directory, which the comment now says.
The stand-ins wrote a ustar tarball and a zip wheel byte by byte, about
ninety lines of format code. The tarball is now made by Bun.Archive and
the wheel by jszip, which @tale/platform and @tale/cli already depend
on. jszip joins @tale/sandbox as a development dependency at the same
exact version, in the workspace lockfile and in the lockfile the spawner
image installs from.

Bun stamps the time into a tarball, so probePackages is asynchronous and
runs once per lab run, and the servers take its result as an option
instead of making their own: the lock files and the servers share the
bytes whose integrity the lock records. The offline test now reads the
archives back with the libraries, which check each checksum.

Real npm ci, pip install --require-hashes and uv pip install installed
the probe packages from the stand-in servers.
The registry cache URL carried its own copy of the dotted-quad octet grammar that network-address.ts already owns and that SANDBOX_EGRESS_PROXY and SANDBOX_INCUS_DNS are read with. The URL pattern now only splits out a host made of digits and dots, and isIpv4Address decides whether it is an address, so one change to that grammar reaches the cache settings too. A test holds the two to each other.
The list refuses a registry host for every request, so with it set a session cannot open a page on pypi.org or registry.npmjs.org, and it cannot install a private package held on registry.npmjs.org even with a token of its own. The contract called browsing and private registries unaffected; it now says that only a private registry on another host keeps working.
The lab case installs through stand-in caches and checks the proxy's refusals, but it never plants a file of a session's own, stops the session and resumes it. That survival is held by the runtime entrypoint's tests, which run it over a home that already holds the file, and the verification list now says so next to the other things the lab leaves out.
The troubleshooting page for refused sandbox network access named only SANDBOX_EGRESS_ALLOWLIST. With SANDBOX_EGRESS_DENIED_HOSTS set, a 403 or an unresolved name for a package registry host is the intended answer, so the page now says that and sends the session to the registry caches, in English, German and French.
The contract test compared the registry host list with the Incus contract and the three environment references, while the env template and the egress proxy's README carry the same four hosts as an example an operator copies. A change to the list now fails there too, and the sandbox test task hashes both files.
@yannickmonney
yannickmonney force-pushed the feat/sandbox-registry-caches branch from 1ee00f5 to c4b2799 Compare October 19, 2026 18:00
@yannickmonney
yannickmonney added this pull request to the merge queue Oct 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 19, 2026
@yannickmonney
yannickmonney added this pull request to the merge queue Oct 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 19, 2026
@yannickmonney
yannickmonney added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit a71d0d9 Oct 19, 2026
@yannickmonney
yannickmonney deleted the feat/sandbox-registry-caches branch October 19, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant