CodeHerderSearch⌘KCtrl KGet started →

Package and browser downloads in containers

How the device download cache speeds up container-stage installs. See which keys it refuses and how to use a private registry.

When a device runs each stage in its own container, CodeHerder gives that device a download cache. Package installs and browser downloads in a stage go through it. A second install of the same package on the same device is fast, and the registry sees fewer requests.

This page covers when the cache applies, what it serves, how to turn it off or cap it, which environment keys CodeHerder refuses because they would change where installs come from, and how to use a private registry.

When the cache applies

The cache runs on a device started with ch device-server --isolation isolated while stage network filtering is on, which is the default. See Isolating agent runs on a device for the two Docker options.

  • One cache serves every task and workspace on the device.
  • It runs on isolated devices only. It does not apply to devices that run stages as plain host processes.
  • It is on by default. You don’t set anything up.

What the cache serves

Tool Served
npm and pnpm Yes
Yarn 2 and later Yes
Yarn 1 (classic) No
Playwright browser downloads Yes
Go modules, and the Go checksum database Yes
Composer: Packagist metadata and GitHub commit zipballs Yes. See PHP and Composer in container stages.
PyPI downloads for pip, uv and other Python clients Yes
Puppeteer browser downloads No. Puppeteer uses the browser that ships in the stage image.

Every other download goes straight to its host, as it does without a cache.

Debian packages in a system image build

A ch-env system image build runs apt against snapshot.debian.org. When the device has a pull cache, the build proxy sends each plain-HTTP GET and HEAD of /archive/ to the cache. The next build on that device reads the .deb files from the cache and fetches none from upstream.

  • A pool/ file is stored. A snapshot URL names a fixed timestamp, so a file never changes.
  • A dists/ index is stored only when its snapshot timestamp is at least 24 hours old. A newer timestamp can still resolve to a later snapshot, so the cache passes it through.
  • apt checks the signatures and hashes itself. The cache does not.
  • The network access rules do not change. The proxy relays a request only when the build’s own rules already allow snapshot.debian.org. Otherwise the request is denied or forwarded as before.
  • If the cache is down, the proxy fetches from snapshot.debian.org itself, and nothing is stored.

Your project’s config still wins

The cache fills in a default only where your project has not chosen. These settings take precedence:

  • A registry or scope registry in a committed .npmrc.
  • A project .yarnrc.yml.
  • A GOPROXY you set yourself, for example with go env -w.
  • A pip index from your own config or requirements file.

Lock files keep the real URLs

A stage never points a package tool at the cache. The tool keeps the real address, such as https://registry.npmjs.org/ or https://pypi.org/. The stage proxy answers for that address and serves the download from the cache.

So a lock file you write in a stage names the real registry. This holds for package-lock.json, pnpm-lock.yaml, yarn.lock, bun.lock, uv.lock, poetry.lock, composer.lock and the output of pip-compile. The lock file works in CI, in Docker builds and on every other machine.

If a proxy or a tool does not support the route, the install skips the cache. It does not fail, and the lock file stays correct.

A push that names the cache is refused

The cache address exists only inside the stage. A lock file that names egress:8888 or /_cache/ breaks npm ci on any other machine.

The device refuses to push a session branch with such a lock file. The error names each file and its fix. For an npm, pnpm, yarn or bun lock file, replace http://egress:8888/_cache/npm/ with https://registry.npmjs.org/. For a Python lock file, replace each cache URL with its https://pypi.org/ or https://files.pythonhosted.org/ URL. For composer.lock, replace http://egress:8888/_cache/packagist/ with https://repo.packagist.org/. Replace each http://egress:8888/_cache/github-zipball/<owner>/<repo>/legacy.zip/<sha> URL with https://api.github.com/repos/<owner>/<repo>/zipball/<sha>. Then commit and push again.

The check reads only the lock files that your new commits add or change. It does not read a push that the agent makes with its own git push.

What gets stored

The cache stores only public, anonymous downloads.

  • A request that carries credentials goes straight to its host. The cache never stores it.
  • A private registry goes straight to its host too.
  • npm packages are checked against the registry’s integrity value, and PyPI files against their published digests, before the cache stores them. Playwright browsers and GitHub zipballs publish no checksum, so those downloads aren’t checked this way. Composer checks a zipball against nothing but its lock entry.

When the cache is down

If the cache isn’t running, installs go straight to the internet. Nothing fails because of it.

The device’s Health panel shows Pull cache as a warning. The warning never blocks work. See Managing your devices for the readiness checks. If you run the device yourself, docker logs ch-pullcache shows why the cache stopped.

Settings

Set these on the device server. See Running the device server as a service for where environment variables go. Restart the device server after you change one.

Setting Default What it does
CH_PULL_CACHE true Set to false to turn the cache off. Installs then fetch from the internet every time.
CH_PULL_CACHE_MAX_SIZE 20g Caps the cache. Use a number with an optional k, m, g or t suffix. When the cache is full, the least recently used entries go first.

When the cache is on, a CH_PULL_CACHE_MAX_SIZE value it can’t parse stops the device server at start.

When the device reaches its disk floor, CodeHerder can empty the cache, late in its cleanup order. It refills as stages ask for packages.

Keys CodeHerder refuses

A key that points installs at another host could send every stage’s downloads somewhere you didn’t intend. CodeHerder refuses a fixed set of keys wherever you can set an environment value:

The save fails with the error code variable_key_refused. The check ignores case, so npm_config_registry is refused too. It applies on every device, whether or not the cache is running.

These are exact names, not patterns. A key not listed here, such as PIP_TIMEOUT, isn’t refused by this rule.

npm, yarn and bun registries

NPM_CONFIG_REGISTRY, NPM_CONFIG_REPLACE_REGISTRY_HOST, NPM_CONFIG_USERCONFIG, NPM_CONFIG_GLOBALCONFIG, YARN_NPM_REGISTRY_SERVER, YARN_REGISTRY, BUN_CONFIG_REGISTRY

Python indexes

PIP_INDEX_URL, PIP_EXTRA_INDEX_URL, PIP_CONFIG_FILE, UV_INDEX_URL, UV_DEFAULT_INDEX, UV_EXTRA_INDEX_URL, UV_INDEX

Go modules

GOPROXY, GOSUMDB, GOPRIVATE, GONOSUMDB, GONOSUMCHECK, GOINSECURE, GOFLAGS, GOENV, GOTOOLCHAIN, GOROOT

Proxies

HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY, YARN_HTTP_PROXY, YARN_HTTPS_PROXY

Composer

COMPOSER_HOME, because its global config can name a repository

Certificate trust

SSL_CERT_FILE, SSL_CERT_DIR, REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE, NODE_EXTRA_CA_CERTS, PIP_CERT, UV_SYSTEM_CERTS, UV_NATIVE_TLS, COMPOSER_CAFILE, COMPOSER_CAPATH

Browser downloads and browser binaries

PLAYWRIGHT_DOWNLOAD_HOST, any PLAYWRIGHT_<BROWSER>_DOWNLOAD_HOST (for example PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST), PLAYWRIGHT_BROWSERS_PATH, PLAYWRIGHT_MCP_EXECUTABLE_PATH, PUPPETEER_DOWNLOAD_HOST, PUPPETEER_DOWNLOAD_BASE_URL, PUPPETEER_EXECUTABLE_PATH, CHROME_PATH, AGENT_BROWSER_EXECUTABLE_PATH

Other keys are refused for other reasons, such as keys that change which program a shell runs. See Variables.

Using a private registry

Put the registry in your project’s own config and commit it. The refusal above doesn’t touch committed files.

  • npm: add a scope registry to the project .npmrc, for example @acme:registry=https://npm.acme.example/.
  • Yarn 2 and later: set npmScopes or npmRegistryServer in the project .yarnrc.yml.
  • pip and uv: put the index in the repo’s pip or uv config, or at the top of a requirements file.
  • Composer: add the repository to the project composer.json. Keep a token in a secret variable, not in auth.json. A package from a private GitHub repo cannot use the zipball cache, because the stage token is stripped. Composer falls back to a source clone, which works only for a repo listed on the task.

Keep the auth token out of the repo. In .npmrc, reference an environment variable:

//npm.acme.example/:_authToken=${NPM_TOKEN}

Then add NPM_TOKEN as a secret variable in the workspace. A name that ends in _TOKEN must be saved with Secret turned on. NPM_TOKEN isn’t on the refused list.

GitLab package registry

Private npm and Composer packages on gitlab.com work in a container stage with no stage secret. CodeHerder relays the registry reads and adds a read-only token itself. The token never enters the stage: not its environment, its files or its logs.

  • It covers the instance-level path /api/v4/packages/npm/ and the project-level path /api/v4/projects/<id>/packages/npm/. Metadata and tarballs both work.
  • Composer works the same way. The group path is /api/v4/group/<id>/-/packages/composer/, where <id> is the numeric group id, with packages.json and the p/ and p2/ metadata. The dist archives come from /api/v4/projects/<id>/packages/composer/archives/. The relay sends the token to GitLab as HTTP Basic, as the Composer API expects. It forwards only the sha query of an archive.
  • The relay sends GET and HEAD only. Publish, dist-tag changes, unpublish and every other gitlab.com API path stay refused, also for a listed repo. A Composer publish is refused too, for the group, for a project named by number and for a project named by path.
  • The token is a deploy token with only the read_package_registry scope. It reads packages in the GitLab connection’s Group or namespace, and in the subgroups below it. It cannot read other groups.
  • CodeHerder first tries a group deploy token. GitLab lets only a group Owner create one. When GitLab refuses it, CodeHerder creates a project deploy token on the one project that owns the package. A Maintainer on that project can create it.
  • A tarball path names its project. For a metadata path, the server looks up the package name in the group’s package list. The project must be inside the connection’s group and hold a package of that type. Each sandbox gets its own tokens. The server revokes them when the sandbox ends.
  • Composer metadata is group-level only, and a project deploy token cannot read a group. With a Maintainer connection, CodeHerder reads the metadata (packages.json, p/ and p2/) on its server with the connection’s own token, and sends your stage only the answer. The group must be the connection’s group or a subgroup. Composer archives still use a project deploy token. So composer update and composer install both work with a Maintainer connection.
  • Your .npmrc can keep its _authToken=${NODE_AUTH_TOKEN} line. pnpm only warns when the variable is empty. The npm CLI fails when NODE_AUTH_TOKEN is unset, so set it to any placeholder for npm.

When the relay refuses a read

A refused read is never a missing npm token. The relay answers 403, sets the header X-CodeHerder-Refusal: <code>, and puts the code and a hint in the status line. pnpm prints it: ERR_PNPM_FETCH_403 ... Forbidden (CodeHerder: <code>; <hint>). npm also shows the hint from the response body. The server log records each refusal with the sandbox, the package and GitLab’s reason. The relay retries a mint that failed because the server was busy or out of reach. It does not retry the other codes.

Never ask a person for an npm token for a relayed registry. No token in the stage can fix a refusal. Do the action in the table.

Code Meaning What the agent does
unavailable, unreachable The server could not mint a deploy token now. Wait a minute and retry. If it persists, retry in a new sandbox.
refused, bad_reply The server refused or garbled the mint. Retry in a new sandbox. Then tell an admin to check the GitLab connection.
sandbox_not_live The sandbox has ended. Retry in a new sandbox.
no_connection The workspace has no GitLab connection. Tell an admin to connect GitLab.
connection_cannot_mint, plan_cannot_mint, no_group_scope The connection or its plan cannot create deploy tokens, or it has no group. Tell an admin to check the connection’s role, plan and Group or namespace.
mint_turned_off Sandbox git tokens is off. Tell an admin.
package_not_in_scope The package is outside the connection’s group, or no project holds it. Check the package name and scope. Do not retry.
unsupported_host, isolation_off, no_server This host, run or device has no relayed registry. Use the committed registry config for that host.
gitlab_refused CodeHerder minted a token, and GitLab refused the read. Tell an admin to check the connection’s access to that project.
mint_failed Any other mint failure. Retry in a new sandbox, then tell an admin.

What it needs:

  • A workspace GitLab connection on gitlab.com with the Group or namespace set to the group that owns the packages.
  • A connection token with the api scope and the Maintainer role on that group. CodeHerder then creates project deploy tokens. The Owner role also lets it create one group deploy token per sandbox. Use a service account that holds the Maintainer role.
  • When the connection cannot create a token, the relay refuses the read. It never falls back to a personal token. The server log names GitLab’s reason.
  • Sandbox git tokens not set to off. Only the server mints this token. When it mints none, the relay refuses the read: a device never uses its own mint key or the token pool for it.
  • A device with a current egress proxy. An older proxy gives the stage no registry route, and installs behave as before.

Self-hosted GitLab hosts are not covered. Use a committed registry config and a secret variable for those.

A writable stage runs with a strict list of allowed hosts, so a private registry host can be blocked at first. When a stage tries it, CodeHerder can turn the block into a request that a person approves. See Network access approvals.

Browsers in container stages

  • Puppeteer uses the browser in the stage image. You need no setup. You can set executablePath to a conventional command such as /usr/local/bin/chromium.
  • Browser commands. chromium, chromium-browser, google-chrome, google-chrome-stable and chrome are on PATH. Check them, and $CHROME_PATH, before you report that no browser exists.
  • Playwright with its own browser needs npx playwright install chromium once per task. The download comes through the device cache and stays for the rest of that task.
  • Playwright with channel: 'chrome', or with executablePath set to a conventional command, needs no install. An empty Playwright cache only means the pinned revision is not downloaded.

Don’t set PLAYWRIGHT_BROWSERS_PATH or PUPPETEER_EXECUTABLE_PATH. Both are refused.

Last updated

Try it on one repository for two weeks.

File a task. An agent builds it. You see the cost of each task.

Try "pricing", "connect a device", or "who reviews the code"

↑↓ move · ↵ open · esc close