Bake your actions into your runner image
The GitHub Actions runner can pick up actions from a local archive cache instead of downloading them for every job. GitHub's own images already use it. Here's how to fill that cache with your own actions on ARC, self-hosted and custom hosted runner images.
Every job that uses an action starts the same way. During Set up job the runner asks GitHub which commit each uses: reference points to, then downloads that repository as an archive and unpacks it. For actions/checkout that's a small download. For a fleet of ephemeral runners that each run hundreds of jobs a day, it adds up to a lot of identical downloads: traffic, time, and one more dependency on GitHub.com being reachable at exactly that moment.
Here's what happens between the runner picking up a job and your first step running:
- The runner receives the job. It doesn't read your workflow files itself. GitHub has already parsed the workflow, including any reusable workflows, and sends the runner a job message that contains the steps for this job.
- The runner collects the
uses:references. It picks out every step that references an action in a repository ($/actions-path,owner/repo@reforowner/repo/path@ref). - With SHA pinning or a lockfile, the commit is already decided. The runner still makes the same call for every action, but the service no longer picks whatever commit a tag or branch points to right now. With a full SHA in
uses:, the ref is the commit. With a workflow dependency lockfile, the locked commit is what runs, including for the actions your actions use. For the cache this matters: because the SHA is known up front, you know exactly which archive to bake into your image, and a tag that moves after you built the image doesn't turn your cache hits into misses. - For any remaining ref that isn't pinned, the runner asks GitHub to resolve them. It sends the list of references to the Actions service in one call. The service turns each
refinto a commit SHA. - On GHE.com, your tenant comes first. GitHub Actions searches your enterprise on GHE.com for each action before falling back to GitHub.com. So
actions/checkoutresolves to the copy on GitHub.com, unless your enterprise has its ownactions/checkout. - The service returns the download information. For each action it sends back the resolved
owner/repo, the commit SHA, the tarball and zipball download URLs and, when provided, a token to download them. If the service doesn't return a token, the runner uses the job's default token. - The runner checks its archive cache. If the runner has a local cache of actions, it looks for
owner_repo/<sha>.tar.gz(Linux, macOS) orowner_repo/<sha>.zip(Windows) and copies it if it's there. The GitHub-hosted images have a small cache of commonly used actions. - Otherwise it downloads the archive. On a cache miss, or when the copy fails, the runner downloads the tarball or zipball from the URL it got back.
- The runner extracts the archive. It unpacks the archive into a temporary folder under
_work/_actionsand copies the single top-level folder to_work/_actions/<owner>/<repo>/<ref>. Note that the folder name is thereffrom your workflow, such asv4, not the SHA. This is the runner's work folder (_workby default, set with--workwhen you configure the runner), not your job's$GITHUB_WORKSPACE. The runner empties_work/_actionsat the start of every job, so even a persistent runner prepares its actions again for every job. With a cache hit, that means extracting a local archive instead of downloading it again. - Composite actions repeat the cycle. The runner reads each downloaded
action.yml. When a composite action uses other actions, the runner resolves, looks up and extracts those the same way, nesting up to a fixed maximum depth.
What the cache changes? A cache hit skips the network download of the archive. It doesn't skip receiving the job or resolving the refs, and with the archive cache described here the runner still extracts the archive for every job.
GitHub solved this for its own hosted runners a long time ago. You can use the same mechanism on your own runners.
The runner already has an action cache
The actions/runner has a little-known feature: the ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE environment variable. When it points to a directory, the runner looks there before downloading an action. The layout is simple:
<cache directory>/
actions_checkout/
<commit-sha>.tar.gz # Linux and macOS
<commit-sha>.zip # Windows
actions_setup-node/
<commit-sha>.tar.gz
The folder name is the action repository with the / replaced by _. The file name is the full commit SHA the action resolved to. On Linux and macOS the runner looks for a .tar.gz; on Windows it looks for a .zip. If the file is there, the runner extracts it locally and never downloads the archive. If it isn't, the runner downloads it as usual. A missing entry never breaks a job.
How GitHub-hosted runners use it
The GitHub-hosted runner images (actions/runner-images) set this variable and fill the folder at image build time. The contents are downloaded by actions/action-versions, it provides configuration for the most popular first-party actions (actions/checkout , actions/setup-node , actions/cache and friends). It includes main and the stable version tags, and each one is pinned to a specific commit SHA.
The image installers put the cache in:
| OS | Cache directory |
|---|---|
| Windows | C:\actionarchivecache |
| Linux | /opt/actionarchivecache |
| macOS | $HOME/actionarchivecache |
That's why actions/checkout@v7 starts almost instantly on a hosted runner: it's already on disk.
The catch: it only covers that curated set of first-party actions. Your own actions, marketplace actions and your organisation's internal actions are still downloaded every time.
Filling the cache with any action you like
gh-actions-archive-cache is a GitHub CLI extension that fills this cache directory for you, using the runner's cache layout and the same numeric version filter as actions/action-versions. It works for any action you choose:
gh extension install jessehouwing/gh-actions-archive-cache --pin v0.0.2
# The 2 newest majors of actions/checkout, with the 3 newest tags of each
gh actions-archive-cache download actions/checkout \
--latest-major-versions 2 --latest-versions-per-major 3 \
--cache-dir /opt/actionarchivecache
# A specific action at a specific ref
gh actions-archive-cache download Azure/login@v2 --cache-dir /opt/actionarchivecache
# Everything recorded in a lockfile, including transitive dependencies
gh actions-archive-cache from-lockfile .github/workflows/actions.lock \
--cache-dir /opt/actionarchivecache
Every ref is resolved to its commit SHA before download. Unlike actions/action-versions, branches such as main are only included when you ask for them explicitly (actions/checkout@main). Tags that point to the same commit share one archive, and files already in the cache are validated rather than downloaded again. It picks zip on Windows and tar.gz on Linux and macOS by default. Use --format both if you build one cache for several operating systems.
If you're doing this on a self-hosted runner or when you're building your own container for Actions Runner Controller, point the runner at the folder you've stored these actions:
gh actions-archive-cache configure --scope runner \
--runner-path /opt/actions-runner --cache-dir /opt/actionarchivecache
This writes ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE into the runner's .env file, which the runner reads when it starts, including when it runs as a service.
Self-hosted runners and Actions Runner Controller
This is where you get the most out of it. With Actions Runner Controller (ARC) or autoscaling VM runners, every job typically starts on a fresh runner with an empty disk, so every job downloads every action again. The official ARC runner image (ghcr.io/actions/actions-runner) doesn't ship a cache and doesn't set ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE, so you have to add both to bake the cache into the image:
# syntax=docker/dockerfile:1
FROM ghcr.io/actions/actions-runner:latest
ARG TARGETARCH
ARG ARCHIVE_CACHE_VERSION=v0.0.2
# The base image runs as 'runner'; switch to root to write to /opt
USER root
# The extension is a standalone binary; you don't need gh in the image to run it
RUN curl -fsSL -o /usr/local/bin/gh-actions-archive-cache \
"https://github.com/jessehouwing/gh-actions-archive-cache/releases/download/${ARCHIVE_CACHE_VERSION}/linux-${TARGETARCH}" \
&& chmod 755 /usr/local/bin/gh-actions-archive-cache
COPY actions.lock /build-inputs/actions.lock
RUN --mount=type=secret,id=github_token \
GH_TOKEN="$(cat /run/secrets/github_token)" \
gh-actions-archive-cache from-lockfile /build-inputs/actions.lock \
--hostname github.com --cache-dir /opt/actionarchivecache --format tar.gz
ENV ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE=/opt/actionarchivecache
USER runner
Build it with docker build --secret id=github_token,env=GH_TOKEN ., push it to your registry and set it as the runner container's image in your gha-runner-scale-set values. The archives are written world-readable (0644), so the runner user can read them without owning them.
The same approach works with Packer, Azure VM Image Builder or any other VM image pipeline. Run the download or from-lockfile commands in a provisioner step, then configure the runner. Pass the token through your build tool's secret mechanism. Never bake a token, a saved gh login or a runner registration token into the image. Do bake in the action source; that's the point. That also means an image holding private actions should only be available to people who may read those repositories.
What you get:
- Less traffic. Each archive is downloaded once per image build, not once per job. That matters when all your runners leave through the same firewall, proxy or NAT gateway.
- Faster job start. Extracting a local file beats downloading it, especially for larger actions or with many actions per job.
- Better availability. If downloading archives from GitHub is slow, rate-limited or briefly unavailable, cached actions still start. Archive downloads are no longer the step that fails your job.
- Your workflows stay exactly the same. The workflows that run on the image need no changes. Only the image build and the runner configuration change.
- Normal
uses:syntax. You keep referencing actions asowner/repo@ref. You don't have to check actions into your repository or vendor them into a folder and call them withuses: ./.... The runner finds the cached archive by itself. - If your runners are connected to a GHE.com tenant and your firewall blocks github.com, a workflow can still use an action like
actions/checkoutas long as its archive is in the cache. The runner still asks your tenant to resolve and authorise the action, so the runner must still be able to reach the tenant, and your allowed-actions policy must still permit the action. The cache only replaces the archive download. A cache miss still needs to download the archive. Anything the action downloads itself (see the caveats below) still needs a network path.
Or: a central cache on a network share
Baking the cache into the image means every new action, or every new version of one, waits for the next image build. For self-hosted runners there's another option: build one central cache on a network share and mount it read-only on every runner.
One trusted host or job owns the share and fills it with the same commands as before:
# On the one machine that may write to the share
gh actions-archive-cache from-lockfile /build-inputs/actions.lock \
--hostname github.com --cache-dir /srv/actionarchivecache --format tar.gz
Each runner mounts the share read-only and points the runner at the mount. On a Linux VM runner that's an ro NFS (or SMB) mount plus configure:
# /etc/fstab on each runner
fileserver:/srv/actionarchivecache /mnt/actionarchivecache nfs ro 0 0
gh actions-archive-cache configure --scope runner \
--runner-path /opt/actions-runner --cache-dir /mnt/actionarchivecache
configure only writes the runner's .env; it doesn't need write access to the cache. On Windows you can point --cache-dir at a UNC path, as long as the runner's service account can read the share.
With ARC, mount a ReadOnlyMany (or ReadWriteMany) persistent volume backed by NFS or Azure Files into the runner container, read-only, and set the variable in the pod spec of your gha-runner-scale-set values. The runner container downloads the actions, so that's the container that needs the mount:
template:
spec:
containers:
- name: runner
image: ghcr.io/actions/actions-runner:latest
command: ["/home/runner/run.sh"]
env:
- name: ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE
value: /mnt/actionarchivecache
volumeMounts:
- name: actionarchivecache
mountPath: /mnt/actionarchivecache
readOnly: true
volumes:
- name: actionarchivecache
persistentVolumeClaim:
claimName: actionarchivecache
readOnly: true
Now adding an action is one download or from-lockfile run against the share. The next job on any runner picks it up, with no image rebuild and no runner restart.
The trade-offs:
- Local network traffic. Every cache hit copies the archive from the share to the runner. That's traffic on your own network instead of the internet, but it isn't free.
- The share becomes part of job start. If the mount point doesn't exist or an archive isn't on it, the runner simply downloads the action, and a failed copy is logged and also falls back to a download. A share that hangs rather than fails, for example an NFS hard mount to a server that's down, can still stall Set up job. Pick your mount options with that in mind.
- Refreshing while runners read.
gh-actions-archive-cachewrites each archive to a temporary.archive-download-*file in the same folder, validates it and then renames it to<sha>.tar.gzor<sha>.zip. The runner only ever looks for the final name, so it doesn't pick up a half-written file, provided the share renames atomically within a folder. Adding archives while runners are busy is fine. Runcleanupwhen runners are idle: the tool's lock file doesn't stop a runner from reading an archive that's being deleted. - Trust. Everything in the caveats below applies, only more so: one writable share feeds every runner. Only the filling process may write to it. Runners and their jobs get read-only access, both in the mount options and in the share's permissions.
GitHub-hosted larger runners and VNet-injected runners
You don't need to run your own infrastructure to benefit. GitHub-hosted runners, including runners injected into your Azure VNet with private networking, already run on images that have the cache directory and the variable configured. They just don't contain your actions.
Custom images for GitHub-hosted larger runners fix that. You build the image with a normal workflow job that has the snapshot: keyword, and anything you put on disk in that job ends up in the image. Add your actions to the existing cache folder:
jobs:
build-image:
runs-on: my-image-generation-runner
snapshot: my-runner-image
permissions:
contents: read
steps:
- uses: actions/checkout@v7.0.2
- name: Install gh-actions-archive-cache
run: gh extension install jessehouwing/gh-actions-archive-cache --pin v0.0.2
env:
GH_TOKEN: ${{ github.token }}
- name: Add our actions to the runner's archive cache
env:
GH_TOKEN: ${{ github.token }}
run: |
gh actions-archive-cache from-lockfile .github/workflows/actions.lock \
--cache-dir "$RUNNER_TEMP/archives"
sudo cp -r "$RUNNER_TEMP/archives/." "$ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE/"
On the Ubuntu images, /opt/actionarchivecache is owned by root. The installer makes the top-level folder world-writable, but the owner_repo folders it extracts from action-versions stay root-owned. Adding a new SHA to actions_checkout therefore needs root, which is why I stage the archives in $RUNNER_TEMP and sudo cp them in. ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE is set in /etc/environment, the same way the image sets variables like ANDROID_HOME, so it's available to your steps.
The example is for Linux. Custom images currently support Linux x64, Linux ARM64 and Windows x64. On Windows the cache is C:\actionarchivecache, set as a machine environment variable, and you can pass it straight to --cache-dir from a pwsh step. If you start from a clean OS base image instead of a GitHub-owned image, there's no cache folder and no variable: create the folder and set ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE yourself.
Every runner that uses my-runner-image now starts with GitHub's curated actions and your own actions already cached. On a VNet-injected runner, that also means less traffic leaving your network.
Two things to keep in mind:
- The job's
GITHUB_TOKENcan read public repositories and the workflow's own repository. To cache actions from other private repositories, use a GitHub App token or a fine-grained token with access to them. - Filling the cache doesn't speed up the job that fills it, because the runner prepares that job's actions before the first step runs. It speeds up every job that runs on the image afterwards.
Keep rebuilding
A cached image is a snapshot. Tags move and new versions ship, so rebuild the image regularly, ideally whenever your lockfile changes. To trim old versions in a long-lived cache, use gh actions-archive-cache cleanup. It applies the same retention rules, previews with --dry-run, and keeps pins it imported from lockfiles plus any lockfile you pass with --lockfile.
Why SHA pinning and lockfiles make this work better
The cache is keyed by commit SHA, not by tag. That has a consequence. If your workflow says uses: actions/checkout@v7 and v7 moves to a new commit after you built your image, the runner resolves the new SHA, misses the cache and downloads the archive. That's safe, just not fast.
With SHA pinning (uses: actions/checkout@<sha> # v7.0.2) or a lockfile generated by github/gh-actions-lock, the exact commit is already fixed in the workflow or lockfile. Nothing on the GitHub side (github.com or your GHE.com tenant) can make it resolve to a different commit. Feed that same lockfile to from-lockfile when you build the image, and every repository action recorded in it, direct and transitive, is in the cache under exactly the SHA the runner will ask for. You get pinning's supply-chain benefits and a cache hit for every locked action from the same file, as long as the image is rebuilt when the lockfile changes.
GHE.com is supported too. Pass --hostname TENANT.ghe.com and put the tenant token in GH_TOKEN. Actions that come from public github.com repositories are downloaded straight from github.com; the tenant token doesn't work there. Provide a github.com token in GH_ACTIONS_ARCHIVE_CACHE_GITHUB_COM_TOKEN (or a saved gh auth login --hostname github.com), otherwise those downloads are anonymous and rate-limited.
Caveats you need to be aware of
The runner trusts the cache implicitly. When the runner finds owner_repo/<sha>.tar.gz (or .zip), it copies and extracts it without checking the contents against the upstream repository. It doesn't compare a hash or a signature. It only checks that the archive extracts and contains a single top-level folder. The SHA in the file name selects which archive to use. It doesn't prove that the archive contains that commit. Anyone who can write to the cache directory, or who controls your image build, can make a job run different code from what the workflow, the SHA pin or the lockfile says.
gh-actions-archive-cache does validate the archives it writes. It resolves the ref to a commit, downloads the archive from GitHub and checks that it's a well-formed zip or tar.gz with one enclosing folder and no unsafe paths before publishing it. Those checks guard against corrupt or truncated files. They don't authenticate the content, and they protect nothing if someone modifies the cache afterwards. So treat the image build and write access to the cache as a trust boundary:
- Build images in a pipeline you control and review, from a reviewed lockfile.
- Make the cache writable only by the image build or trusted administrators. Runner accounts need read access, not write access.
- Don't let jobs on a persistent runner write to a cache that later jobs use.
Actions that download more at runtime. The cache contains the action's repository archive and nothing else. Some actions download more when they run: they call npm install, use curl to fetch a binary, pull a container image or download a tool. The archive cache doesn't contain those extra payloads. Unless something else already provides them, such as a tool cache, a pre-pulled image or a package mirror, the action still needs network access to fetch them, and on a locked-down runner that can fail. Check what your actions do at runtime before you rely on the cache in a restricted network.
The full documentation, including Windows and macOS examples and an image acceptance checklist, is in the gh-actions-archive-cache repository.