outerlayer runner init sets built-in
hooks, which run each build in a
container or a microVM.
Write your own hooks to give builds an isolation of your own, such as a cloud
VM or a sandbox that your platform team runs. The runner runs the provision
hook before the build’s command and the cleanup hook after it. It runs an
optional report hook at both ends. See
What happens to one build.
What changes with hooks of your own
A runner on hooks of your own differs from a runner on built-in hooks:- A build works in one repository.
- The build holds the item key. The runner serves no gateway or Claude address to it.
- The runner runs no housekeeping. Your cleanup hook removes what a build leaves.
- The runner takes no runs of a schedule automation.
- A comment that you send to the agent does not reach a running build. It starts the next agent job.
runner.autoUpdateis off unless you set it.
Name the hooks
Name your scripts in therunner block of the runner’s
config file:
provision and cleanup are required, and both must be your own. report is
optional and is never a builtin: value.
Hooks are executables, commands are shell lines
Each value is the absolute path of an executable. The runner runs it directly: no shell, no arguments, no variables expanded."/opt/outerlayer/provision.sh" works. "$HOME/bin/provision.sh" and
"/opt/outerlayer/provision.sh --fast" fail with an error that names the
path. Put arguments and expansion inside the script.
The build’s command line runs through /bin/sh -c, so variables in it expand.
The build’s variables
Every hook and the command receive the variables in Variables a build receives, and so does everything they start. They name the factory, the item key, the item’s number, the folder of the build’s files and logs, the branch and the commit identity. They also inherit the runner’s own environment, except anyOUTERLAYER_*
variable and the secrets that a destination’s header names.
An agent other than Claude Code needs a session-start hook that reads
OUTERLAYER_WORK and links the session.
For anything else about the item, call the CLI:
work status also carries the issue’s body, as issue.body.
Time limits
A hook that writes nothing to its log forrunner.idleLimitMinutes (30 by
default) gets SIGTERM, then SIGKILL. The log shows
#9 provision idle for 30m, ended. No hook runs longer than
runner.timeLimitMinutes (480 by default). So print progress.
A provision hook that the runner ends this way fails the build. A cleanup or
report hook that it ends this way leaves the build’s outcome as it was.
The provision hook
The runner runs the provision hook before the command, in$OUTERLAYER_JOB_DIR. The hook prepares the place the command runs in, and
writes where that is to provision.out.
The hook receives the build’s variables and these:
provision.out
The hook writeskey=value lines to $OUTERLAYER_JOB_DIR/provision.out:
An
exec, broker or recipe value that the runner cannot use fails the
build at provision, and the reason names the key.
The runner puts the checkout on $OUTERLAYER_BRANCH when workdir is a git
checkout on the host. When workdir is inside the isolation, the hook must
check out that branch itself.
How the runner calls exec
The runner starts exec with these arguments:
/bin/sh -c 'cd -- "$0" && exec "$@"' <workdir> <command>. Run all of them
inside the isolation, as the agent’s user.
The runner starts exec with the build’s variables in its own environment.
Pass them into the isolation, or the command does not see them. With Docker,
docker exec -e NAME passes the variable NAME on.
The runner runs more than the build’s command through exec: outerlayer sync and outerlayer work proofs. So the isolation needs outerlayer on its
PATH.
The tunnel and the proxy
The runner serves the build’s tunnel on the socket$OUTERLAYER_BUILD_DIR/tunnel.sock. A build through an exec reaches the
tunnel in one of two ways.
A broker address. When the isolation can reach an address on the host,
write broker=<ip>:<port> to provision.out. The tunnel also listens there,
and HTTPS_PROXY and its siblings name that address. The tunnel needs no relay.
With Docker’s default bridge network on Linux, a container reaches the host at
172.17.0.1. A provision.out for such a container holds these lines:
$OUTERLAYER_BUILD_DIR into the isolation, and run a relay in the isolation’s
network. With no broker key, HTTPS_PROXY and its siblings name
127.0.0.1:3128. Make that port reach the tunnel:
outerlayer --help does not list outerlayer broker-relay. These flags are
its supported interface:
A build through an
exec reaches a destination
only on a relay port, whether or not you set broker. The first destination
is on port 3129, the second on 3130, and so on, in the order of
runner.build.destinations. Relay each port with --forward.
Only a tool that reads the proxy variables reaches the tunnel. A task runner
that filters the environment hides them from its tasks. See
When a task runner hides the proxy variables.
Maven
Maven ignores the proxy variables. With anexec, the runner points Maven at
the tunnel. It writes a settings file and puts --global-settings <file>
first in MAVEN_ARGS. The runner never writes to your ~/.m2, and your own
~/.m2/settings.xml still applies.
Maven gets no proxy from the runner in these cases:
- Maven is older than 3.9, which does not read
MAVEN_ARGS. - Your
MAVEN_ARGSnames a global settings file with--global-settingsor-gs. The runner keeps your value, and the build’s log says so. Add the tunnel as a proxy in your own settings file. - The runner cannot write the file, and the build’s log says why. It writes
the file in the checkout’s git directory. So the isolation needs
git, andworkdirmust be a git checkout. - The file’s path has a space in it.
Exit status
- Exit 0 runs the command. A
workdirthat does not exist fails the build with outcomefailed. - Exit 75 (
EX_TEMPFAIL) declines the item: this runner cannot take it now, for example with too little disk free. The runner releases the claim with no outcome, and the item stays queued for another runner or a later poll. - Any other non-zero exit fails the build with outcome
failed.
workdir. It must not wait for input.
The cleanup hook
The runner runs the cleanup hook after the command, however the command ends. It runs the hook again on recovery, for a build that the runner lost. The hook receives the build’s variables and these:OUTERLAYER_OUTCOME:ok,failed,timed_out,idle,lease_lost,interruptedorstopped. It is empty when provision exited 75. Outcomes and reasons explains each. It isokfor any command that exited 0, even when the build later ends asincomplete.OUTERLAYER_LOG: the path of the command’s output log.OUTERLAYER_BUILD_DIR: so the hook can unmount what it mounted there.
$OUTERLAYER_JOB_DIR for inspection. Remove those files
yourself when you no longer need them, because the runner does not.
The cleanup and report hooks may write a reason to
$OUTERLAYER_JOB_DIR/reason. The runner sends its first line with the build’s
outcome, cut to 200 characters. A reason that the runner words itself, such as
an out-of-memory kill, replaces it.
The report hook (optional)
Use the report hook to tell people about a build, for example with a comment on the issue. The runner runs it twice:
At the end,
OUTERLAYER_OUTCOME is the build’s final outcome, incomplete
included. See
When the command exits 0.
The hook also runs for an item that the provision hook declines with exit 75.
OUTERLAYER_OUTCOME is then empty at the end. Post nothing in that case, or
the hook comments on every decline.