CodeHerderSearch⌘KCtrl KGet started →

Giving stages the tools they need

Declare the tools, system packages and setup script your stages run with, preview changes before you save, and fix a stage waiting on a build.

An agent can only use the tools its device has. If your project needs jq, a Go toolchain, or a Postgres client, you can declare them once and CodeHerder makes sure each stage has them. That declaration is the environment. This page covers how to set one up, how to check what a stage gets, and what to do when a stage waits because no device can build it.

If you need a whole custom container image instead, see Running a stage in your own container image. The two don’t mix for system packages; see System packages below.

How an environment works

You pin each tool to an exact version. CodeHerder checks the pinned set once and records the result. Before a stage starts, the device that will run it installs those exact tools. Two stages with the same tools share one build, so the cost is paid once per device.

An environment is built from layers. From widest to narrowest:

  1. Group. A group workspace’s environment applies to every workspace below it.
  2. Workspace.
  3. Workflow. Applies to every stage of that workflow.
  4. Stage. Applies to one stage.

The rules are the same everywhere:

  • Tools: the narrowest layer that names a tool wins. A workflow or stage can also remove a tool that a wider layer declared, for the stages it covers.
  • Setup scripts: every layer’s script runs, in layer order, widest first. See Running a stage in your own container image for how a setup script behaves.
  • System packages: the packages from all layers are added together. A narrower layer can’t remove a package a wider one declared.

Where to manage it

In the web app, go to Settings → Environment. The page shows these sections:

  • Inherited from groups: tools from the groups above this workspace. Read only here.
  • This layer: the tools this workspace or group declares.
  • Setup script: the script this layer runs before the agent starts.
  • Workflow and stage overrides: the layers narrower than the workspace.
  • Effective environment: what a given stage ends up with.
  • Resolve status and Version history: described below.

A group’s page leaves out the overrides, effective environment and resolve status, because they only make sense for a workspace.

A workflow’s own page and a stage’s own page (Settings → Stages) each have an Environment section for that layer.

Only a workspace admin who is a person can change an environment. An agent’s credential is refused. Everyone else sees the pages read only.

Add a tool

In the web app, open This layer, choose Add tool, then From registry. Search for the tool and pick a version from its releases. The Custom tool option is for a tool that isn’t in the registry; it asks for a name, version, download URL template, the binaries to put on the command path, a sha256 for at least one platform, and optional replacements.

From the CLI, find the tool and its releases first:

ch env search pup
ch env releases DataDog/pup

Then pin the version you want:

ch env tools add DataDog/pup 1.23.7

A tool name is one of:

  • a registry name, such as DataDog/pup;
  • npm:<package>, pip:<package> or go:<module> for a language package.

The version is always exact. A range, or latest, is refused. A custom tool can’t be added with ch env tools add; write it with ch env set instead, which replaces the whole workspace environment from a JSON file. Run ch env show --json to see the shape.

To remove a tool this layer declared:

ch env tools delete DataDog/pup

Per-workflow and per-stage layers

Add --workflow <key> or --stage <key> to put a tool in one workflow’s or one stage’s layer instead of the workspace layer:

ch env tools add --stage review jq 1.7
ch env tools add --workflow story docker/compose v2.29.7

To drop a tool that a wider layer declared, for one stage or workflow only, add --remove-inherited:

ch env tools delete --stage review --remove-inherited go

In the web app, the Add tool menu has Remove inherited tool for the same job.

System packages

If a stage needs an operating system package, declare the Debian package name. You don’t pin a version.

ch env system add postgresql-client libvips42
ch env system delete libvips42
ch env system add --stage review jq

For more control, ch env system dockerfile --from-file system.Dockerfile sets a Dockerfile fragment for the layer. A fragment can’t start a new image with FROM, and it has a size limit of 16 KiB.

System packages build on the CodeHerder base image. For a build that needs another host, see When a build needs another host. A write is refused while a stage in scope sets its own container image, and the message names those stages. A device that can’t build the packages shows as ineligible in the device matrix described below.

A Dockerfile fragment needs an isolated device. A device that is not isolated shows the image as ineligible with the reason “a Dockerfile fragment needs an isolated device”. Placement then uses an isolated device. If none exists, the stage waits and the blocker names the reason and the fix: start one with ch device-server --isolation isolated. A sys:<package> cap does not change this. A lock with packages only works on every device.

Feature Isolated (container) Isolated (microvm) Unisolated (host)
System packages Built into an image Built into the same image Checked only; a sys:<package> cap covers a missing one
Dockerfile fragment In the image In the image Refused
Workflow and stage layers Folded into the lock Same Same fold; packages checked
Build egress approvals Yes Yes Not used: nothing is built
Pull caches Yes Yes Not provided
Git and release relays Yes Yes Not provided
Tools Read-only mount Same On PATH

Packages that cannot be installed on the base image

The base image carries patched builds of some libraries. A Debian -dev package needs the exact version of its library. The snapshot has only the Debian build, so apt refuses the install. The build fails with a message like Depends: zlib1g (= ...) but ... is to be installed.

Library Version on the base image Packages that fail
gcc-14 14.2.0-19+ch1 gfortran-14, gccgo-14, gdc-14 and other gcc-14 packages the image does not carry
krb5 1.21.3-5+deb13u1+ch2 libkrb5-dev and other krb5 packages the image does not carry
git 1:2.47.3-0+deb13u1+ch1 No additional version conflict: git-svn, git-email, git-gui and git-all accept this patched 2.47.3 version range
brotli 1.1.0-2+ch1 libbrotli-dev
libexpat1 2.10.0-1 libexpat1-dev

To change a library, use one of these workarounds:

  • For expat, install the matching security build in a fragment: apt-get install -y --allow-downgrades libexpat1=2.9.0-1~deb13u1 libexpat1-dev=2.9.0-1~deb13u1. It has the same upstream fix.
  • For gcc-14, a downgrade to the Debian build is possible. It brings back the fixed CVEs, so do not use it unless you accept that risk.
  • Set a container image for the stage that already has the packages.

When a build needs another host

A system image build reaches only the Debian snapshot and the hosts a device owner allows. A Debian package in a fragment resolves from the snapshot. A third-party host, such as packages.sury.org, fails the build.

When that happens, CodeHerder files a request for each blocked host. The task blocker names the host. To approve it:

  • In the web app, open the workspace Dashboard and its Network access approvals panel. Choose Always allow in this workspace.
  • From the CLI, list the requests, then approve one for the workspace:
ch egress list --purpose build --status pending
ch egress approve <requestId> --scope workspace

To approve a host before a build asks, create a build rule:

ch egress rules create packages.sury.org:443 --purpose build --yes

Keep these points in mind:

  • A rule rebuilds the image. The old ready image serves stages until the new one is ready. Approve all the hosts of one build together to save rebuilds.
  • A rule belongs to one workspace. A group does not pass its rules down. If a group-level fragment needs a host, add a rule in each workspace.
  • A build rule never opens the host to an agent session.
  • A device owner can refuse workspace build hosts on that device. That device then shows the image as ineligible.
  • Debian packages stay pinned to the snapshot. A third-party repository is not pinned, so a rebuild can pick a newer package. Pin the package version (php8.5-cli=<version>) and the sha256 of each download where you can.

See Network access approvals and PHP and Composer in container stages.

Keep secrets out of setup scripts and Dockerfile fragments

CodeHerder refuses to save a setup script (before_stage) or a Dockerfile fragment that contains a real credential. The check runs at every layer: workspace, workflow and stage. It also runs on the environment overrides of an Evaluation.

The reason is simple. Every member of the workspace can read these two fields, and CodeHerder sends them to your devices. A password typed into one would be visible to all of them.

The check looks at the shape of the text, not at variable names. It catches things like a private key block, a cloud access-key ID, an API token, and a password inside a URL such as https://user:password@host/repo. A placeholder like https://${GIT_TOKEN}@host/repo passes, because it holds no value.

When a save fails, the message names the field (before_stage or system.dockerfile). It never repeats the value. A revert to an old version that holds a literal credential is refused the same way. A layer you saved before the check existed still loads and runs, but your next edit has to remove the credential.

Pass a secret to a setup script

Store the value as a secret variable, then read it from the script by name:

printf %s "ghp_your_token_here" | ch variable set GIT_TOKEN --secret --from-file -

Then write the script without the value:

git clone "https://${GIT_TOKEN}@github.com/acme/private-tools.git" /tmp/tools

The script reads GIT_TOKEN from its environment, in a stage container and on a host device that runs setup scripts. Use an uppercase name. A lowercase secret never reaches the environment.

A secret variable needs no device approval. Any device that runs the stage receives it.

Dockerfile fragments get no secrets

A fragment is built into an image before any session exists, so no secret variable is available while it builds. $GIT_TOKEN is empty there. Do not try to fetch from a private source inside a fragment.

Keep the fragment to public packages. Do the private fetch in the setup script, which runs when the stage starts.

Preview a change, then save

Before you save, review what the change reaches. In the web app, Save changes stays disabled until you choose Review changes. The review lists each stage the change reaches, its tool changes, and the devices that must build.

From the CLI, write your layer to a file and preview it. Nothing is saved:

ch env diff --from-file env.json
ch env diff --workflow story --from-file workflow-env.json
ch env diff --stage review --from-file stage-env.json

Without --workflow or --stage, the file is the workspace layer, in the same format as ch env set takes. With them, it’s the environment object that ch env show --json prints for that layer.

See what a stage gets

The Effective environment section picks a workflow and a stage and lists every tool, package and script with the layer it comes from, plus the build state on each device.

From the CLI:

ch env show --effective --task <taskId>
ch env show --effective --workflow story --stage review

With --task, the stage defaults to the task’s current stage. ch env show with no flags prints the workspace layer on its own.

Confirm a source change

After you save, CodeHerder checks each tool again in the background. If a tool’s source moved since the last check, such as a new repository or download host, a person has to confirm it. This stops a changed download location from reaching your devices unnoticed.

A tool set that already had a good result keeps using it until you confirm. A tool set that is new has nothing to fall back on, so its stages wait.

To see what is waiting and confirm it, use the Resolve status section, which shows each pending source change and a Confirm button. From the CLI:

ch env lock
ch env diff
ch env diff --confirm

ch env lock --resolve starts a fresh check now. Confirming is for workspace admins who are people. An agent’s credential is refused.

Check the build on each device

Each device builds the environments its stages need. In the web app, open Devices → Environments. The matrix has one row per environment and one column per device. Each cell shows one state:

State Meaning
ready The device has the tools.
building The device is installing them.
pending The device hasn’t started.
failed The build failed. The cell shows the reason and the time of the next retry.
ineligible This device can’t run this environment, for example because of its platform. The cell shows why.

A failed build retries by itself, with longer waits between tries. To read a failure, open its build log from the cell. To retry sooner, choose Rebuild on a failed or ready cell. The device must be online.

A system package build that fails on a blocked network host files a network access request for an admin. See Network access approvals.

The same data is in the CLI:

ch env status
ch env status --device build-01
ch env log --device build-01 3f2a9c1d4b7e
ch env rebuild --device build-01 3f2a9c1d4b7e

The hash is from ch env status. A unique start of it is enough. Only a workspace admin who is a person can rebuild.

When a stage waits

If no device can run a stage’s tools, the task doesn’t start. Instead, CodeHerder puts a blocker on the task. The blocker starts with “No device can run this stage’s tools”, then names the tool and platform, or points at the failed build. Run ch task blockers <taskId> to read it. The task’s activity also shows a start refused entry. The blocker clears by itself when a device can run the tools. You don’t need to do anything to restart the task.

To fix it:

  1. Run ch env status or open Devices → Environments and find the failed or ineligible cells.
  2. Read the reason, or the build log for a failure.
  3. Fix the cause. Common ones are a tool with no build for the device’s platform, or a download that fails. Then choose Rebuild, or link a device that can run it.

If the cause is an unconfirmed source change, confirm it as described above. For other start problems, see Why isn’t my task moving?.

Tools only reach stages that CodeHerder starts on a device. A dev session and a task you run on your own machine (see Run a task on your own machine) don’t get the workspace’s tools.

History and revert

Every save writes a new version. Version history on Settings → Environment lists them, and the workflow and stage pages show their own layer’s history.

ch env versions
ch env versions --stage review
ch env revert 1
ch env revert --workflow story 2

A revert doesn’t rewind history. It writes the old content as a new version, so you can see what happened. ch env revert --stage review 2 restores only that stage’s environment and leaves the rest of the stage as it is now.

If someone else saves while you edit, your save is refused. Reload and apply your change again.

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