A CI/CD runner has to execute steps written in languages it was never built for. A Go runner may need to run a Node.js test suite, a Python linter, or an AI agent built on the Claude Agent SDK. Most systems answer this with one of three approaches, and each one gets harder to maintain as the number of runtimes grows.
The Problem with Traditional CI/CD Runners
Most CI/CD systems end up choosing between three options.
Option 1: Monolithic runner. Embed Node.js, Python, Go, Ruby, and other runtimes in the runner binary or its image.
- The runner grows with every runtime it supports.
- Updating one runtime means rebuilding and redeploying the whole runner.
- Runtimes bring conflicting system libraries and version pins.
- You can never cover every language and version that users need.
Option 2: Plugin architecture. Define a plugin interface and load plugins at runtime.
- The plugin API becomes a versioned contract that you must keep stable.
- Plugins still need a runtime, so the runner embeds one indirectly.
- Plugins often run inside the runner’s own process and user, so the security boundary is thin.
Option 3: Shell everything. Run run: npm test through a shell on the host.
- Easy to start and easy to understand.
- No filesystem, network, or process isolation between jobs.
- Resource limits are whatever the host happens to provide.
- A buggy or malicious workflow can read other jobs’ workspaces and the runner’s credentials.
Each option trades flexibility, isolation, and maintenance effort in a different way. Execution Images draw the boundary at a different place: the container.
The Execution Images Pattern
Core idea: a Docker image is the execution boundary. The runner starts a container from an image, passes it a workspace and a job description, collects its output and exit code, then removes it. Everything runtime-specific lives inside the image.
+-------------------------------------------+
| Control Plane (Go, Java, Python, ...) |
| - REST API |
| - Job queue and scheduling |
| - Database and secret policy |
+-------------------+-----------------------+
| claims jobs, sends workflow
v
+-------------------------------------------+
| Runner (language-agnostic) |
| - Pulls images |
| - Creates and starts containers |
| - Streams logs, reads exit codes |
| - Enforces resource and security limits |
+-------------------+-----------------------+
| Docker API (create, start, wait)
v
+-------------------------------------------+
| Execution image (runtime-specific) |
| |
| node:24 + workflow executor + actions |
| python:3.12 + pytest + dependencies |
| golang:1.23 + build tools |
+-------------------------------------------+
The key insight
The runner does not need to know what runs inside the container. It needs only five capabilities:
- Pull an image.
- Create and start a container with resource and security settings.
- Pass input: a workspace mount and environment variables.
- Collect output: the log stream and the exit code.
- Manage the lifecycle: stop, remove, and clean up, even after a crash.
This contract is small and stable. Supporting a new language means building a new image. The runner’s code does not change.
How It Works
The flow has three parts. A workflow names an image. A runner starts that image. The image knows how to run the steps.
1. Workflow definition
name: ai-code-review
jobs:
review:
image: myorg/claude-agent:1.2.3@sha256:4f1c9a2e7b... # tag for people, digest for machines
steps:
- uses: myorg/claude-review@v1
with:
prompt: "Review this PR for bugs"
model: claude-sonnet
The image field sits on the job because the runtime belongs to the job. One workflow can run a Python test job and a Go build job, each in its own image.
2. Runner execution
The runner below is Go. The same five Docker calls work from Java, Python, or any language with a Docker client. Error handling is trimmed where it does not change the design.
package runner
import (
"context"
"fmt"
"io"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
)
// RunJob executes one job in its execution image and returns the exit code.
func RunJob(ctx context.Context, cli *client.Client, job Job) (int64, error) {
// 1. Pull the image. Drain the progress stream, or the pull may not finish.
pull, err := cli.ImagePull(ctx, job.Image, types.ImagePullOptions{})
if err != nil {
return -1, fmt.Errorf("pull %s: %w", job.Image, err)
}
defer pull.Close()
if _, err := io.Copy(io.Discard, pull); err != nil {
return -1, fmt.Errorf("pull %s: %w", job.Image, err)
}
// 2. Create the container with the workspace mount, limits, and hardening.
pidsLimit := int64(1024)
created, err := cli.ContainerCreate(ctx,
&container.Config{
Image: job.Image,
WorkingDir: "/workspace",
Env: job.Env, // secrets arrive here at runtime, never in the image
},
&container.HostConfig{
Binds: []string{job.WorkspaceHost + ":/workspace:rw"},
Resources: container.Resources{
NanoCPUs: 2_000_000_000, // 2 CPUs
Memory: 2 << 30, // 2 GiB
PidsLimit: &pidsLimit,
},
CapDrop: []string{"ALL"},
SecurityOpt: []string{"no-new-privileges"},
NetworkMode: container.NetworkMode(job.NetworkName),
}, nil, nil, "")
if err != nil {
return -1, fmt.Errorf("create: %w", err)
}
// Remove the container even when ctx was canceled, so nothing is left behind.
defer cli.ContainerRemove(context.Background(), created.ID,
types.ContainerRemoveOptions{Force: true})
// 3. Register the wait before starting. Use next-exit: a created but
// unstarted container counts as "not running", so that condition returns at once.
statusCh, errCh := cli.ContainerWait(ctx, created.ID, container.WaitConditionNextExit)
if err := cli.ContainerStart(ctx, created.ID, types.ContainerStartOptions{}); err != nil {
return -1, fmt.Errorf("start: %w", err)
}
// 4. Stream stdout and stderr. stdcopy splits Docker's framed stream into
// the two writers. Without it, both streams arrive mixed together.
logs, err := cli.ContainerLogs(ctx, created.ID, types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
})
if err != nil {
return -1, fmt.Errorf("logs: %w", err)
}
defer logs.Close()
logsDone := make(chan error, 1)
go func() {
_, err := stdcopy.StdCopy(job.Stdout, job.Stderr, logs)
logsDone <- err
}()
// 5. Read the exit code, then let the log copy finish so the final lines are kept.
select {
case status := <-statusCh:
<-logsDone
return status.StatusCode, nil
case err := <-errCh:
return -1, fmt.Errorf("wait: %w", err)
case <-ctx.Done():
return -1, ctx.Err()
}
}
job.Stdout and job.Stderr are io.Writer values that forward each line to the log store. job.Env is a []string built from the job’s variables and secrets.
That is the whole runner contract. It has no Node.js, no Python, and no knowledge of the workflow’s steps. It creates a container, passes it an environment, and reads the result.
3. Execution image implementation
The image holds the runtime, the libraries, and the code that runs the steps:
FROM node:24-bookworm-slim
WORKDIR /app
# Install production dependencies first so this layer caches across code changes.
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --prod --frozen-lockfile
# Action implementations and the workflow executor
COPY dist/ ./dist/
# Run as the non-root user that ships with the official Node image
USER node
CMD ["node", "dist/runner.js"]
The image contains:
- The Node.js runtime
- The Claude Agent SDK (
@anthropic-ai/claude-agent-sdk) and the Claude Code CLI it drives - Action implementations, which are the reusable steps a workflow calls
- A small workflow executor that reads the job from the environment
None of this is visible to the runner. It sees an image name, an environment, and a workspace.
Real-World Example: Claude Agent SDK in CI
Suppose your Go-based CI/CD system needs an AI code review step built on the Claude Agent SDK. The SDK is a TypeScript package, and it expects a Node.js runtime and a native Claude Code binary. Here are the two ways to get it running.
The traditional approach
- Embed Node.js inside the Go runner, or shell out to a Node binary installed on the host.
- Install the SDK and its native dependencies on every runner host.
- Build and test per platform (linux-x64, linux-arm64, darwin-arm64) because native binaries differ.
- Keep the host Node version and the SDK version in sync across all runners.
- Upgrade the SDK by changing every runner host, or by rebuilding the runner that embeds it.
Every SDK upgrade becomes a runner release. A runner bug becomes an SDK problem, and the reverse.
The Execution Images approach
1. Build the execution image (the Dockerfile from the previous section).
2. Implement the workflow executor. This file runs inside the container and calls the SDK:
// dist/runner.js (compiled from src/runner.ts)
import { query } from "@anthropic-ai/claude-agent-sdk";
const workflow = JSON.parse(process.env.WORKFLOW_JSON ?? "{}");
const apiKey = process.env.ANTHROPIC_API_KEY;
if (!apiKey) {
console.error("ANTHROPIC_API_KEY is not set");
process.exit(2);
}
for (const step of workflow.steps) {
if (step.uses !== "myorg/claude-review@v1") {
console.error(`unknown action: ${step.uses}`);
process.exit(2);
}
for await (const message of query({
prompt: step.with.prompt,
options: {
model: step.with.model,
cwd: "/workspace",
permissionMode: "acceptEdits",
},
})) {
// One JSON object per line. The runner forwards each line to the log store.
console.log(JSON.stringify(message));
}
}
The executor fails fast on a missing key and on an unknown action. Those two checks matter more than they look. A typo in a workflow should stop the job with a clear error, not silently skip a step.
3. Reference the image in the workflow:
jobs:
review:
image: myorg/claude-agent:1.0
steps:
- uses: myorg/claude-review@v1
with:
prompt: "Review this PR for security issues"
model: claude-sonnet
4. The runner stays generic. The Go code from the previous section starts the container and forwards logs. It never imports the SDK.
Before and after
| Concern | Embed in runner | Execution image |
|---|---|---|
| Runner language | Must host Node or bridge to it | Stays pure Go |
| SDK upgrade | Rebuild and redeploy the runner | Build a new image tag |
| Native binaries | Built per host platform | Built once per image platform |
| Runtime conflicts with other jobs | Shared host runtime | Each job has its own filesystem |
| Rollback | Redeploy an older runner | Change the tag in the workflow |
| Host footprint | Node on every runner host | Only Docker is required |
The image is large, but the image is pulled once per host and cached. The runner binary stays small and changes rarely.
Actions: Reusable Steps Live in the Image
A workflow should not embed code in YAML:
# Avoid: inline code makes every workflow a copy of the same logic
steps:
- name: review
script: |
import { query } from "@anthropic-ai/claude-agent-sdk";
// 50 lines of code...
Package the logic as a named action instead:
# Prefer: a versioned action implemented in the execution image
steps:
- uses: myorg/claude-review@v1
with:
prompt: "Review for security issues"
Action implementations live in the execution image and are versioned with it. Two properties follow from that:
- A workflow pins an image tag, and the tag pins the action code. Both change together.
- Fixing an action means publishing a new image. Workflows that pin the old tag keep working.
Implementation Guide
Here is how to build this in an existing runner. The example uses buller, a Go CI/CD system whose Docker backend already follows the pattern.
Step 1: Define a backend interface
Keep the runner’s job loop independent of Docker details:
type Backend interface {
Execute(ctx context.Context, job *models.Job, workflow *models.Workflow) error
Name() string
Close() error
}
Buller’s internal/runner/backend/backend.go declares this interface. A second backend, such as a Kubernetes job runner, could implement it later without changing the control plane.
Step 2: Implement the Docker backend
Buller’s Docker backend does three things per job:
- Creates a per-job bridge network.
- Pulls the job’s image and creates a container that runs
sleep infinity, with the workspace mounted. - Runs each step as a
docker exec, streams its output withstdcopy, and removes the container and network at the end.
A long-lived container with exec-per-step keeps one filesystem and one environment across steps. That matters for workflows where step two depends on files written by step one. The lifecycle is more involved than the single docker run in the earlier sketch, so the cleanup path has to be deliberate. Buller removes containers and networks even after a failure, using a context that outlives the canceled job.
Step 3: Create execution images
For each runtime, build an image with:
- The runtime and its pinned version
- Its dependencies
- The workflow executor
- The action implementations it supports
Keep each image focused. An image that contains every runtime becomes the monolithic runner again, only inside a container.
Step 4: Extend the workflow schema
name: string
jobs:
<job-name>:
image: string # new: execution image reference
steps:
- uses: <action>@<version>
with:
<parameters>
Make image required or give it a documented default. A missing image should fail validation at submit time, not at run time.
Step 5: Pass the workflow into the container
Send the workflow through an environment variable for small payloads, or mount a file for large ones:
Env: []string{
"WORKFLOW_JSON=" + workflowJSON,
fmt.Sprintf("JOB_ID=%d", job.ID),
"ANTHROPIC_API_KEY=" + apiKey, // injected per job, see Security below
}
Environment variables are visible in docker inspect to anyone with Docker access on the host. For secrets, prefer a file mounted read-only into the container, or a short-lived token issued per job.
Why This Works
Clean separation of concerns
The control plane decides what runs, when, and for whom. The runner decides how to run a container. The execution image decides how a step runs.
Control plane knows: the jobs, their schedule, their owners, and their permissions.
Runner knows: how to talk to Docker, how to stream logs, and how to enforce limits.
Execution image knows: the runtime, the libraries, and how to interpret the workflow.
Each layer can change without breaking the others. A new SDK version touches only the image. A scheduler change touches only the control plane.
No dependency hell
Consider the earlier comparison with a Go SDK. A runner that wants to call a Node-only SDK faces three problems: the Node runtime, the native binaries, and the build matrix. Execution Images remove all three from the runner. The image carries them, and the runner needs only the image name.
Multiple runtimes, no conflicts
One system can run jobs in several images at once:
jobs:
ai-review:
image: myorg/claude-agent:1.0
python-tests:
image: python:3.12-slim
go-build:
image: golang:1.23
custom-tool:
image: acme/proprietary-analyzer:2.1
Each job gets its own filesystem, its own Python or Node version, and its own dependency tree. Two jobs that need different libssl versions never meet.
Versioning that works
Pin the exact image by digest for reproducible runs:
image: myorg/claude-agent:1.2.3@sha256:4f1c9a2e7b...
A tag alone is a pointer that can move. A digest is a content hash that cannot. Use the tag for humans who read the workflow and the digest for the runner that executes it. Semver ranges such as ^1.2.0 need a registry resolver. Docker does not resolve them, so avoid them in the runner unless you build that resolver.
Rollback means changing the tag or digest back to a known-good value. The runner needs no change, and the previous image is still in the registry.
Security by default
Each job runs in a container with:
- Resource limits: CPU, memory, and process count.
- Dropped capabilities:
CapDrop: ALL, so the container gets no Linux capabilities. - No privilege escalation:
SecurityOpt: no-new-privileges. - Network isolation: a per-job network, so jobs cannot reach each other. Egress control needs a proxy (see Network policy below).
- Scoped host mounts: the workspace is the only host path mounted into the container.
These defaults come from Docker’s own controls. The runner sets them on every container, so a workflow author cannot turn them off.
Security Considerations
Execution Images move untrusted code into containers. That reduces the blast radius, but it does not remove the risk. Treat each item below as required.
1. API keys and secrets
Never bake secrets into an image. An image is copied to every host that pulls it, and its layers stay in the registry history.
# Never do this. The key is in the image history forever.
ENV ANTHROPIC_API_KEY=sk-...
Inject secrets at runtime, per job, and scope them to that job:
Env: []string{
"ANTHROPIC_API_KEY=" + secrets.Fetch(ctx, job.ID, "anthropic"),
}
Prefer a secret manager that issues short-lived tokens. Revoke the token when the job ends. Keep secrets out of logs: the runner should redact known secret values from the log stream before they reach the log store.
2. Network policy
A review job needs the Anthropic API and the repository host. It does not need the internet. Attach each job to a dedicated network and allow egress only to those destinations, typically through an egress proxy with an allowlist:
NetworkMode: container.NetworkMode(job.NetworkName), // per-job network
// Route HTTPS through an egress proxy that allows only approved hosts.
A bridge network with no proxy still allows all outbound traffic. Do not describe that setup as isolated.
3. Resource limits
Always set limits. A runaway loop without a limit can take down the host:
Resources: container.Resources{
NanoCPUs: 2_000_000_000, // 2 CPUs
Memory: 2 << 30, // 2 GiB
PidsLimit: &pidsLimit, // max processes, stops fork bombs
},
Buller’s defaults are 2 GB of memory and 1024 PIDs, both set in internal/runner/backend/docker/config.go.
4. Image provenance
- Use a private registry for enterprise workloads.
- Scan images for known vulnerabilities before they are allowed to run.
- Sign images and verify the signature before the runner starts a container. Docker Content Trust and Cosign both support this.
- Pin by digest so that a compromised tag cannot change what runs.
5. Workspace isolation
Each job gets its own workspace directory, and the container sees only that directory:
Binds: []string{
fmt.Sprintf("/tmp/jobs/%d:/workspace:rw", job.ID),
},
Never mount the Docker socket into an execution container. A container with the socket can start other containers with any mount, including the host root filesystem. That turns one compromised job into a compromised host.
Operational Benefits
Independent updates
Update the SDK? Build and push a new image:
docker build -t myorg/claude-agent:1.3.0 .
docker push myorg/claude-agent:1.3.0
The runner keeps running. New jobs that reference 1.3.0 pull it. Jobs already running keep their image.
Gradual rollout
Route a subset of jobs to a new image by changing the reference in the workflow or in a control-plane setting:
# Canary: a small share of jobs
image: myorg/claude-agent:1.3.0
# Stable: the default for everything else
image: myorg/claude-agent:1.2.3
Rollout control belongs in the control plane, which can pick the image per job. The runner only follows the reference it receives.
Easy rollback
Found a regression? Point the workflow back at the previous tag or digest. The previous image stays in the registry, so the runner pulls it like any other image.
Caching
Docker layer caching keeps builds fast. Order the Dockerfile so that stable layers come first:
# Rebuilt only when the lockfile changes
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --prod --frozen-lockfile
# Rebuilt on every code change
COPY dist/ ./dist/
On the runner side, the image is pulled once per host and reused by later jobs, so the cost of a large image is paid once.
Testing
Test an image without starting the whole CI/CD system:
docker run --rm \
-v "$PWD/workspace:/workspace" \
-e WORKFLOW_JSON='{"steps":[{"uses":"myorg/claude-review@v1","with":{"prompt":"Review"}}]}' \
-e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
myorg/claude-agent:test
The same image that runs in production runs here, so a passing local run is a meaningful check.
When NOT to Use This Pattern
Execution Images add real cost. They make sense when the cost buys isolation and independent versioning.
Simple shell steps. If the workflow is only run: npm test on one trusted repository, a container per job adds latency without much benefit. Run the command with docker exec into a single long-lived container, or on the host if the code is trusted.
A single runtime. If every job is Go, the runner can embed the Go toolchain directly. The indirection buys nothing.
Tiny scale. For a personal project with a handful of jobs a day, the operational overhead of image builds, registries, and digests may outweigh the benefit.
Latency-sensitive jobs. A cold image pull adds seconds or minutes. Keep base images small and pre-pull the common ones on runner hosts.
Comparison with Other Patterns
| Approach | Strengths | Weaknesses |
|---|---|---|
| Monolithic runner | Simple to start, no image management | Heavy binary, version conflicts, slow to update |
| Plugin system | Flexible, extensible | Complex API contract, weak isolation |
| Shell everything | Easy to write and debug | No isolation, no resource limits |
| Execution images | Clean separation, isolation, per-job versioning | Requires Docker, image build and registry work |
| Kubernetes pods | Scheduling, isolation, scaling built in | Cluster to operate, more moving parts |
Execution Images and Kubernetes pods solve the same problem with the same primitive, a container image. Pods add a scheduler. If you already run Kubernetes, use pods. If you do not, a Docker-based runner gets most of the benefit with far less infrastructure.
Real-World Adoption
The same boundary appears in systems that many teams already use:
- GitHub Actions runs a
uses:action in a Docker container when the action is a container action. - GitLab CI uses the
image:keyword to choose the environment for each job. - Tekton runs each task step in a container from a specified image.
- Argo Workflows runs each workflow step as a Kubernetes pod with its own image.
This pattern is established. Buller applies it to a Go runner with a Docker backend.
Conclusion
The Execution Images pattern gives you:
- Clean separation: control plane, runner, and execution image each have one job.
- No dependency hell: the runtime and its libraries live in the image.
- Multiple runtimes: Node, Python, Go, or a proprietary tool, side by side.
- Security by default: containers with dropped capabilities, limits, and scoped mounts.
- Independent updates: push a new image, and the runner stays unchanged.
- Versioning that works: pin by digest, roll back by changing a reference.
The pattern has costs. Docker must run on every runner host, images need a registry and a build pipeline, and secrets and network policy need deliberate design. When isolation and independent versioning matter, those costs are worth paying.
Stop embedding runtimes in your CI/CD runner. Let Docker be the execution boundary.