> ## Content Index
> Fetch the complete content index at: https://debugly.dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# Running Agents in CI Needs Budgets, Gates and a Kill Switch
- URL: https://debugly.dev/agents-in-ci-budgets-kill-switches/
- Published: 2026-10-09T03:30:00.000Z
- Updated: 2026-10-17T05:57:03.000Z
- Description: The pipeline gained an autonomous step and, with it, a workload that could loop, spend and touch production at three in the morning.
- Author: Rohit Bhadani
- Tags: DevOps, AI, Tooling

The CI pipeline acquired an agent step the way pipelines acquire things: a plugin, a helpful action, a one line addition that "lets the agent fix lint and regenerate the lockfile". For weeks it was fine. Then a dependency release changed the lockfile resolver's behaviour, the agent's regeneration looped, the step ran for four hours, burned a month of compute budget, and opened pull requests against eleven repositories, because the agent's credential scoped wider than anyone remembered. The step was a workload, and the pipeline had given a workload no budget, no gate and no off switch.

I have run this failure in production myself, and the fix below is the one I now reach for first.

This is the argument that an autonomous step in CI is a deployment, of a binary you did not review, that runs with your credentials, and it must be operated like one.

This was a CI system with an agent action holding a repository write token, and every control below is one the incident proved missing.

## The agent step is a deployment, so it gets a budget

A deployment gets resource limits, and the agent step gets the same: a wall clock cap, a compute cap, a token or cost cap, and an outbound request cap, enforced by the runner, not by the agent, because a budget the workload enforces is a suggestion. The four hour run becomes a ten minute run that fails loudly, which is the difference between an alert and a bill.

The cost cap is the newest one and the easiest to skip, because compute budgets are familiar and token budgets are not. But the agent's tokens are the pipeline's spend, and an unbounded token budget is an unbounded line item that some other team's prompt change can move, which is the billing cousin of [the token bill is a performance metric](https://debugly.dev/agent-token-bill-as-performance/).

## The agent step is a deployment, so it gets a gate

A deployment does not run on the protected branch without a gate, and the agent's output gets the same rule: the agent proposes, the gate disposes. Its changes land as a pull request that a separate approver merges, per [an agent should never merge its own pull request](https://debugly.dev/agents-should-not-merge-their-own-prs/), which is why the two fixes look alike.

The gate also checks the blast radius: how many files, how many repositories, how many external calls. The eleven pull requests were one radius check away from being one, and the radius check is cheap because the step's mandate is narrow by design.

## The agent step is a deployment, so it gets a kill switch

A workload gets a stop button, and the agent step gets one that works from outside the agent, because a loop that can only be stopped by the loop is not stoppable. The kill switch cancels the runner job, revokes the step's short lived credential and closes its egress, in that order, and it is one command a human can run at three in the morning, per the sandbox discipline in [the sandbox checklist for letting an agent touch real tools](https://debugly.dev/agent-sandbox-checklist/).

The credential being short lived is what makes the kill switch real. A long lived token keeps working after the job dies, which is how a cancelled step keeps opening pull requests, and the revocation on cancel is the control that ends the story.

## The credential is the real perimeter

The incident's widest damage came from the token, so the token gets the most attention: scoped to the one repository the step needs, write access only to the branch it proposes on, no organisation scope, short lived, and logged on every use. The pipeline already has this discipline for deploy credentials in [CI pipeline secrets and least privilege](https://debugly.dev/ci-pipeline-secrets-least-privilege/), and the agent step is not special, it is a consumer of the same discipline, newly impatient.

The rule of thumb is that the agent's credential should be weaker than a junior engineer's, because the agent is faster than a junior engineer and asleep less, and speed plus privilege is the product that makes incidents expensive.

## Observability for the step you did not write

The agent step needs the same instrumentation as any service: its duration, its spend, its outbound calls and its produced diffs, logged where the pipeline's other metrics live, and alerted on the p99, because the agent's tail is where the loops live, per [event loop lag is the metric nobody alerts on](https://debugly.dev/event-loop-lag-metric-nobody-alerts/) in spirit. The four hour run was visible in the duration metric from minute eleven, and nobody was alerted, because the step had no metric, because it was "just CI".

## The takeaway

An autonomous step in CI is a deployment of unreviewed code with your credentials, and it gets a deployment's controls: runner enforced budgets on time, compute, tokens and requests, a gate that turns its output into a proposal, a kill switch that cancels the job and revokes the short lived credential, a credential weaker than a junior engineer's, and metrics with a p99 alert.

The plugin that adds the agent is one line. The controls are the difference between that line being a productivity win and being the longest CI run in your company's history, opening pull requests at three in the morning with nobody awake to say stop.

One more control earns its place because CI agents inherit the pipeline's trust: run the agent step in the same sandbox you would give any untrusted job, with the network allowlist and the disposable filesystem, so that even a compromised or confused step finds nothing to reach. The pipeline already isolates arbitrary third party build scripts in some mature setups; the agent step is a third party build script that can talk back, and it gets the same isolation, without argument, as part of the definition of done for the step.

---

Published on [debugly.dev](https://debugly.dev/) by [Rohit Bhadani](https://debugly.dev/about/) | Founder of [Krova Cloud](https://krova.cloud/?ref=debugly.dev)