Est.

Why Infrastructure-as-Code Discipline Requires Agents to Live in the Same Repo as the Systems They Touch

Agent permissions belong in the repo, where review can see them.

· 8 min read
Cover illustration for “Why Infrastructure-as-Code Discipline Requires Agents to Live in the Same Repo as the Systems They Touch”
Agent Governance · November 11, 2026 · 8 min read · 1,864 words

Agents-as-code means defining AI coding agents in version-controlled configuration files, including YAML, in the same Git repository as the systems they may change. Those definitions should go through the same pull request review and CI validation as infrastructure code. Infrastructure-as-Code discipline extends to agents only when their capabilities are reviewable in the repo, enforced through scoped credentials and isolated execution, and verified through attributable audit trails.

How IaC became the accountability layer for infrastructure changes

Infrastructure-as-Code addressed an accountability problem that provisioning automation alone could not solve. With infrastructure defined in versioned configuration files and changes routed through review, each change has an author, a reviewer, a timestamp, and a rollback path. The repository becomes the record of approved intent. Declarative definitions show what should exist, state management links those definitions to deployed resources, and CI validation tests a change before apply.

A configuration file does not protect production if someone can bypass its review and deployment process. A pull request gives reviewers a place to check what a change will do before it takes effect. An IaC change can open a network path, grant a permission, or provision costly resources as soon as it is applied. The review gate therefore protects more than code quality.

What actually changes when an AI agent starts writing IaC

Barrak et al. (2026) studied hundreds of thousands of IaC pull requests across tens of thousands of GitHub repositories and found agent traces in a growing share of submissions. Agents are already consequential contributors to infrastructure repositories. The study found that agent PRs are about four times larger than human PRs and more often modify core infrastructure modules, while bots mainly maintain dependencies.

Larger changes place more demands on review. Disclosed agents also create new infrastructure more often than humans, introducing new permissions, costs, and attack surface. The study found that disclosed-agent PRs were less likely to merge even after controlling for change type and repository context. That result could reflect closer review or submissions that are harder to review, but it proves neither.

Drift adds a separate source of uncertainty. Gruntwork identifies that AI assistants do not inherently know when deployed infrastructure has diverged from the repository. An agent may therefore reason from code that no longer describes production. Reviewing its diff remains necessary, but the diff alone cannot establish that its assumptions about the environment were sound.

Why agent configuration is infrastructure — and must be treated as such

Agent configuration is a class of infrastructure definition. Terraform declares the desired state of cloud infrastructure, while agent configuration declares what a runtime should let an agent do. Both set boundaries that affect what happens outside the file. For an agent, those boundaries can include filesystem access, secrets, external network endpoints, and production APIs. A permissive definition can expose an entire execution environment to autonomous action.

Cycode maps specific configuration failures to concrete blast radii. An unrestricted filesystem path lets an agent read SSH keys and credentials. Without a network policy, exfiltration to any external endpoint is possible, and a wildcard host rule lets an agent connect to attacker-controlled servers. A well-formed infrastructure diff does not compensate for the permissions used to produce it.

Claude Code distinguishes instructions in CLAUDE.md from permissions in settings.json, with instructions shaping what the agent tries to do and permissions defining what it is allowed to do. That distinction belongs in the review model. Instructions, tool definitions, and enforceable permissions all influence a session, but only controls backed by the execution environment can constrain its authority.

How do you store AI agent definitions in Git for normal code review?

A canonical agent job specification belongs in the repository the agent is authorized to change. It can declare the repository target, objective, constraints, CI and wall-clock time budgets, maximum model cost, and an explicit production-deploy permission flag. YAML provides a declarative form for that specification.

Co-location makes capability changes visible to the same review process that protects infrastructure changes. Git records who changed a definition and when, and CI can reject overprivileged policies or missing constraints before deployment. Reviewers can inspect the agent’s authority in the context of the system it will touch. A committed specification also removes hidden UI or database settings from the declared configuration, although it does not make model outputs deterministic.

Gruntwork states the operational boundary plainly through its distinction between diffs and deployments. The agent proposes changes, while humans and deployment pipelines handle apply. When capability settings live outside the repo, the infrastructure PR cannot show everything the agent was allowed to do. A separate system may retain its own history, but that history is not the repository’s review and validation chain.

What the permission model must look like when agents write IaC

Version control establishes what was approved, but credentials determine what an agent can actually do. Gruntwork identifies the foundational constraint as withholding permissions and credentials that would let the agent destroy infrastructure. Prompt instructions cannot provide that guarantee on their own. Deny rules and other soft controls can be ignored or worked around, whereas authority withheld at the credential layer is unavailable to the agent.

The default posture is read-only access to production. An agent can read Terraform code and suggest changes without having credentials that allow apply. Where a session needs access, short-lived tokens should be injected at runtime and scoped to the required operations. Long-lived AWS credentials, production write access, and repository secrets exposed to all workflows undermine that boundary.

An agent might legitimately read secrets for a configuration task and legitimately open external pull requests, yet those capabilities together form a credential-exfiltration path. Each grant cannot be assessed in isolation. Cycode connects overly permissive tools, inherited high-privilege credentials, dynamically fetched tools and MCP servers, and unsandboxed execution to distinct agent risk categories. The engineering implication is that repo policy, credential scope, tool access, and execution controls must agree on what the session may do.

What the sandbox and execution environment must provide for agents touching IaC

Runtime isolation makes the repository’s declared boundaries enforceable during execution. Without it, an agent able to run arbitrary commands may corrupt a developer’s local environment or affect other jobs on shared CI infrastructure. Isolation alone is also incomplete. If a sandbox policy changes without review, it can enforce a boundary that no one in charge of the infrastructure approved.

The sandbox needs enough context to support informed changes. That includes the cloned repository, dependency graph, test suite, CI configuration, deployment manifests, and the environment variables required for the session. Context is not a license for unrestricted access. The agent needs to see how the parts of the system it works on fit together, with credentials and network permissions limited to its task.

Cycode compares this with the move in cloud security toward checking configuration before deployment. Finding an exposed resource after deployment cannot undo the exposure that has already happened. Static analysis of agent configuration and runtime enforcement therefore serve different purposes, identifying vulnerable policy before use and constraining execution when the agent acts. Credentials complete this boundary only if their lifetime matches the session. They must be minted for that session, scoped to its operations, and revoked when it ends.

Observability and audit trails as the verification layer for agent IaC changes

Configuration records intended authority, while an audit trail records its use. AgentS4D, a 2026 benchmark study of risk-injected runs, found that 66.22% of runs both triggered a prespecified unsafe signal and met their case-specific completion predicates. External verifiers assessed completion and unsafe signals. The result demonstrates that successful completion cannot certify safe execution.

Production observability must therefore extend beyond the final diff. It must capture every tool call, its input and output, and every generated diff, attributed to the person or trigger that initiated the session. Token consumption belongs with tool calls and retrieval activity so that cost anomalies can be examined with behavioral anomalies. Sudden token spikes, repeated calls against the same resource, and sessions that run past their expected wall-clock time must all be visible.

A Terraform module change can affect downstream resources whose exposure is not obvious in the diff, so observability must surface that impact before changes ship. Attribution then connects the execution record to an accountable decision. If an incident follows, the trail must lead from production impact through the agent’s actions to the person who initiated or approved the session.

Running agents on managed infrastructure rather than laptops or shared CI

The execution venue follows from these control requirements. Claude Code on a laptop can write Terraform, but that capability says nothing about the governance of its session. A developer’s laptop shares credentials, environment variables, and filesystem access across running processes. Shared CI can likewise expose jobs to one another or leak secrets across workflow runs when sandbox isolation is absent.

Managed execution must be assessed by what it enforces. The relevant criteria are isolated sessions, session-scoped credentials, budget limits, and attributable tool-call logs, with policies derived from reviewed configuration. A remote host is not sufficient by itself.

Budget enforcement belongs in that same decision. Agentic workflows consume far more tokens per task than standard interactions, and uncontrolled loops can accumulate substantial costs before a session ends. Per-session budget caps must therefore be enforced at the gateway layer. A configuration file can declare a maximum model cost, but only the execution system can stop spending at the boundary. That is the same division of responsibility that governs permissions, with the repository declaring the limit and the runtime enforcing it.

What engineering teams should do before the next agent PR touches production IaC

The first step is to audit existing agent configuration and its review history. CLAUDE.md, AGENTS.md, settings.json, MCP server configurations, and orchestration workflow files are all in scope. This audit costs nothing and shows where the system is exposed now. Teams should distinguish instructions from enforceable permissions, then identify files added without review and any capability grants that bypassed the infrastructure approval process.

The next step is to bring those definitions under explicit branch protection and required review in the system’s repository. A YAML agent specification that grants production-deploy permission should need the same approval as a Terraform change that opens a firewall rule. CI validation should run at the same stage as IaC linting and security scanning. It should check for overprivileged tool definitions, missing network constraints, and production-deploy flags set to true before configuration is deployed.

Credentials must then be checked against those declared controls when the agent runs. Any agent session with production write credentials presents a standing risk that should be remediated before the next session runs. The default remains read-only access to production. Runtime enforcement must then match the reviewed specification through isolated execution, session-scoped credentials, budget caps, and attributable action logs.

Finally, add a repository-level CI check for remote backend configuration. The same study by Barrak et al. found that agents introduce sustainability smells at a rate of 10.4%, nearly identical to human authors. Missing remote state and similar issues are therefore problems across the repository that both agents and humans can introduce. A remote-backend check would catch most of these smells regardless of authorship and costs nothing to add.

Sources

  1. Do AI Coding Agents Write Infrastructure as CodeLike Humans? An Empirical Studyof GitHub Pull Requests
  2. [2610.34613] Do AI Coding Agents Write Infrastructure as Code Like Humans? An Empirical Study of GitHub Pull Requests
Filed underAgent Governance

More in Agent Governance