Skip to content
Yassir Kachri

Agentic Software Factory

Running Coding Agents in CI/CD Without Standing Secrets

A pipeline agent reads text written by outsiders and will eventually follow an instruction nobody in the organization wrote. How job-scoped identity, unreachable credentials, a model-free publish job and a sandbox bound what it can do.

Yassir Kachri Updated 10 min read

A pipeline agent runs where nobody watches it. A job starts from a merge request or a button, calls claude -p, and ends with a branch, a label or a verdict. No engineer reads the transcript while it runs, and the job routinely reads text written by people outside the organization: dependency READMEs, vendored code, test fixtures, the diff of a pull request. Any of that text can carry instructions.

I design a pipeline agent on the assumption that it will, at some point, follow an instruction its owners did not write. Detection of injected text is probabilistic, so I do not rely on it. The job is built so that such a session can do little harm: it can read the checkout, reach the package mirror and commit to its own branch, and every commit then meets the same verification stations as any other change. The only cloud credential in the job expires with it and sits where the agent’s tools and shell are refused, and the right to push belongs to a separate job that runs no model.

The Nx compromise shows what an agent CLI adds to a breach

“On August 26, 2025, malicious versions of several Nx packages were published to npm,” according to the maintainers’ post-mortem, which traces the cause to their own pipeline: “Attackers exploited a GitHub Actions injection vulnerability to steal our NPM publishing token and publish malicious packages for 4 hours.” The malicious packages “scanned user systems for sensitive data, attempted to use local AI tools (like Claude and Gemini), and uploaded the results to a public GitHub repo via the GitHub CLI.” The sources do not say which options the payload passed to those tools or on how many machines the attempt succeeded, so the incident illustrates the risk without measuring it.

It carries two lessons. The first concerns the workflow: a pull request title was pasted into a shell command, so the injection needed no model at all. The reference workflows in my book never place pull request text in a run: body; prompts are fixed strings, and the only interpolated values are repository names, numbers and a work-item ID validated against a pattern. The second concerns the agent: whoever can run code on a machine that holds credentials can also drive the agent CLI installed there, with whatever access the machine has. The rest of the design makes sure that, on a runner, there is little to borrow.

Exhibit 1 Each rule bounds what a pipeline agent can do after it follows an injected instruction
RuleControl in the reference designWhat it bounds
Identity comes from the jobOIDC exchange for one-hour credentials; trust limited to the platform repository’s workflowsA stored key that outlives the job
Credentials sit out of the agent’s reachA profile file denied to Claude’s file tools and to the sandboxed shell; the OIDC token unset after useAn injected instruction reading the credential
No job that runs a model can pushThe agent commits; a separate job with no model pushesAn injected instruction publishing code
Agent-written code runs with no identityCredentials deleted before the tests run; a test job with no cloud identity and no stored Git tokenA hostile test stealing a credential
Every agent job sits behind a kernel boundarySingle-use gVisor or Firecracker runners; one logging proxy with a short allowlistExfiltration, and anything left behind on the runner

Source: Author's reference design, The Enterprise Agentic Software Factory.

Identity comes from the job and expires with it

No pipeline in the reference design stores a model-provider key. Each job that calls a model requests an OIDC token from the CI platform and exchanges it for short-lived cloud credentials. On GitHub that means id-token: write and the cloud provider’s credentials action; on GitLab, id_tokens and an STS exchange with a documented duration of 3,600 seconds.

The detail that matters is the subject the cloud role trusts. Claude Code’s guide for GitHub Actions on cloud providers scopes it to repo:your-org/your-repo:*, which is too wide for this purpose: any workflow on any branch of the repository can request a token with that subject, including a workflow file a pull request adds, which runs on the pull_request event before anyone reviews it. GitHub lets an organization include job_workflow_ref in the subject claim and “configure the sub condition to require that claims must include a specific value for job_workflow_ref.” The reference design uses that to trust only the platform repository’s workflows. GitHub documents the claim for reusable workflows and says nothing about workflows required through rulesets, so I would confirm on a test repository, before the condition goes live, that a workflow added by a pull request is refused.

The role itself can invoke models and do nothing else. A credential taken from it can spend model tokens on the organization’s account until it expires, which is the worst case the rest of the design works to bound.

Credentials must sit where the agent’s tools cannot reach

A credential that lives for an hour still has to live somewhere. Two documented behaviors frame the choice. Sandboxed shell commands inherit the environment “from Claude Code, including any secrets in its environment,” and “There is no built-in credential deny list, so only the files and variables you list are restricted.” The AWS credentials action, by default, exports credentials as environment variables, which every process the job starts can read.

The reference design keeps credentials out of the environment. On GitHub, the action’s aws-profile input writes them “to ~/.aws/credentials and ~/.aws/config files instead of env variables,” and only the step that starts Claude Code names the profile. On GitLab, the job writes the exchanged credentials to the same profile file and unsets the OIDC token as soon as it has served. A managed settings file in every runner image then denies Claude’s file tools on the credential directories:

{
  "permissions": {
    "deny": [
      "Read(~/.aws/**)",
      "Read(~/.ssh/**)",
      "Read(~/.docker/**)"
    ]
  }
}

The documentation describes these rules as a “best-effort attempt” across the built-in tools that read files, and it applies them to shell commands it recognizes, such as cat. The sandbox adds its own denyRead on ~/.aws and ~/.ssh for every shell command. Claude Code’s own AWS client still reads the profile, which is the point of the file.

The agent commits and a separate job pushes

An agent that can push can publish anything an injected instruction asks for. The reference implementer commits, because commits are the output of its work, and cannot push. The end of the job is ordered deliberately:

    # Agent-written code runs below. No credential remains.
    - rm -f ~/.aws/credentials
    - |
      first=$(jq -r .result result.json | head -n 1)
      case "$first" in SPEC-QUESTION:*)
        echo "Back to the Spec Gate" >&2; exit 1 ;;
      esac
    # Never trust the agent's own claim that tests pass.
    - make test bdd
    - git bundle create agent.bundle "$CI_COMMIT_SHA..HEAD"

The credentials file is deleted before any step runs code the agent wrote. A reply that starts with a spec question fails the job and returns the item to its owner. The full suite then runs outside the agent’s session, and only then is the work written to a bundle. A second job, which runs no model and reads no outsider’s text, pushes that bundle with the design’s one standing secret: a push credential stored as a protected variable, scoped to a deployment environment, and absent from the agent’s job. The pipeline definition itself lives in a platform project the agent cannot write to, so no edited pipeline can declare that environment.

The reference implementer runs on GitLab. A team that adds one on GitHub keeps the same split, and its publish step needs its own identity for a second reason: GitHub “doesn’t trigger workflows on commits made with the default GITHUB_TOKEN,” so a branch pushed with that token would never meet the critic. The book’s answer is a GitHub App installation token that the implementer never receives.

The jobs that run agent-written code on the pull request hold no cloud identity at all. The tests job has no id-token permission, checks out with persist-credentials: false so no Git token stays on disk, and runs on an isolated runner whose proxy decides what leaves.

Exhibit 2 The credential, the shell and the push right sit in different places, and one proxy is the only route out

A CI job exchanges its OIDC token for one-hour credentials, which are written to a profile file. Inside a single-use gVisor or Firecracker runner, the agent session's file tools are denied that file by deny rules, and its sandboxed shell is denied it by the sandbox and can reach only the package mirror. Hooks run outside the sandbox and can read the file. The file is deleted before the tests run agent-written code. The agent commits to a bundle, and a separate publish job with no model holds the only push credential. All traffic leaves through a host proxy that logs every request and allows the model provider, the token exchange, the mirror, telemetry, the log store and the CI platform.

Source: Author's diagram of the pipeline plane in The Enterprise Agentic Software Factory.

The sandbox confines the shell, and deny rules confine the tools

Claude Code’s sandbox confines shell commands with bubblewrap on Linux, and its documentation is exact about the boundary: “The sandbox covers shell commands only. Claude’s file tools, MCP servers, and hooks run outside it.” Each control therefore covers one path, and the design pairs them: the sandbox for the shell, deny rules for the file tools, and the runner’s own boundary for everything that runs outside both.

Three sandbox settings matter most in a pipeline. failIfUnavailable makes Claude Code exit at startup when the sandbox cannot start, instead of running commands unsandboxed. allowUnsandboxedCommands: false stops a blocked command from being retried outside the sandbox. And the network allowlist holds the internal package mirror and nothing else. The documentation warns that broad domains such as github.com “can create paths for data exfiltration,” and a single internal mirror leaves little room for that. Claude Code’s own requests to the model provider are not shell commands; they leave through the host proxy described below.

The same boundary has a consequence for the test gate. The hook that runs the suites before the agent may finish runs outside the sandbox, so in the implementer session it executes code the agent has just written, with the job’s user, network and files, including the credentials file. I keep the gate in the pipeline because it gives the agent the same feedback loop it has on a workstation. The exposure is bounded by layers that do not depend on Claude Code: the runner is single-use, its only route out is a proxy that logs every request, and the credential it could read invokes models and expires within the hour. A team that finds that bound too loose can disable the hook for CI sessions and have the agent run the tests through its sandboxed shell.

Every job gets a kernel boundary of its own

The sandbox and the deny rules are controls inside one operating system. My rule for placing jobs is that any job whose agent has a shell or reads content from outside the organization runs on gVisor or Firecracker, and every job is single-use. gVisor intercepts system calls in a user-space kernel, at the cost of “higher per-system call overhead” and “reduced application compatibility.” Firecracker gives each job a guest kernel behind hardware virtualization, with socket-only egress to the host. Every agent job in the reference design reads a diff or a dependency tree that an outsider may have shaped, so all of them run on these two pools, the implementer on gVisor and the review jobs on Firecracker. Underneath both, the job runs in a rootless container with no capabilities, a read-only root and no network of its own. The host proxy allows the model provider, the token exchange, the package mirror, the telemetry collector, the log store and the CI platform’s endpoints. On the GitHub pool the list also includes the Anthropic host that the Claude GitHub App uses for its token exchange. The CI endpoints are the widest residual route out, because they accept writes, and the proxy log is where such a request would appear.

Brakes are graduated by scope and drilled

Because identity is issued per job, the widest pipeline brake is simple: remove the agent role’s OIDC trust and revoke its older sessions. New jobs fail at their next role assumption, and credentials already issued stop working once the identity service propagates the revocation. Narrower levers come first. One work item can be reassigned to an engineer, and one GitLab project can be taken off agent authoring by setting a protected variable, which stops new pipelines and lets running jobs finish. The operating rule is to pull the narrowest lever that covers the blast radius and widen only if the signal persists. Each lever is drilled once a quarter on a test project, and the measured time from decision to effect is the one the incident runbook uses.

Workload identity also simplifies offboarding. When an engineer leaves, agent jobs need no change, because they hold repository identity and never a person’s. The exception is GitLab scheduled pipelines, which run with their owner’s permissions and have to be reassigned before the account is removed.

Questions a CISO should be able to answer

  • Which jobs that run a model hold a stored key or a push credential today?
  • What subject does each agent role trust, and has a workflow added by a test pull request been refused?
  • Where do the job’s credentials sit while the agent runs, and which of the agent’s tools can read them?
  • What can the implementer’s runner reach on the network, and where is that traffic logged?
  • How long does it take to stop every pipeline agent, measured in the last drill?