Model-Native Agency in Coding Agents: New Security Risks and Governance Models

Sweet team

|

November 23, 2026

Coding agents now plan, run shell commands, edit files and push commits within a single model-driven loop. That model-native agency moves the real security decision from the prompt to the terminal. This article argues that coding agent security has to be governed where agents act, on the workstation and in the pipeline, because prompt wrappers never see what actually executes.

Key Takeaways About Coding Agent Security

  • When planning and tool choice live inside the model's weights, there is no reviewable plan before execution. The same task can produce different commands on different runs, so controls must judge actions as they happen.
  • CLI agents inherit the developer's shell, files, git identity and network path. Securing them is endpoint and identity work, not a chat-filtering problem that application-layer guardrails can solve.
  • Agents optimized to make tests pass can sometimes delete assertions or loosen security settings to get there. Diffs touching tests, auth or infrastructure deserve their own review path.
  • Signed, attributable agent commits and short-lived agent identities make it possible to scope an incident quickly and to compare what an agent was allowed to do with what it did.

Run AI on a secured infrastructure.

See Sweet secure your cloud-native applications and AI agents in one platform, in a 30-minute walkthrough.

What Model-Native Agency Actually Means for Coding Agents

Every point above traces back to one design change: where the agent's decision-making lives.

From External Orchestration Harnesses to RL-Trained Autonomous Loops

Early coding assistants ran inside an orchestration harness. An external program decided when to call the model, parsed its output and chose which tool to run next. Security teams could read that harness. The control flow was ordinary code that someone wrote, reviewed and versioned, and governing it made perfect sense.

Model-native agency inverts that arrangement. Many current coding models are trained, at least in part, with reinforcement learning on long, multi-step tasks: read the repository, run the tests, interpret the failure, edit, retry. Much of the planning, tool selection and decision to stop now lives in the model's learned behavior rather than in external code. The harness shrinks to a thin shim that executes whatever the model asks for.

The consequence is easy to understate. The sequence of actions isn't written anywhere before the agent starts. Two runs of the same task against the same repository can produce different commands, different files touched and different network calls. Non-deterministic shell execution is a property of the design, not a defect. A plan that doesn't exist until runtime can't be reviewed in advance.

Why Terminal-Native Tools Change the Developer Attack Surface

Terminal-native agents run as the developer's own user, in the developer's own shell. Whatever that session can reach, the agent can reach too. A typical terminal session hands an agent a broad set of capabilities.

  • Shell access: Arbitrary command execution, including interpreters, package managers and build scripts.
  • Filesystem reach: The home directory, cloud credential files, kubeconfigs, SSH keys and .env files from every project on the machine.
  • Git identity: Configured credential helpers, signing keys and push rights to every repository the developer can write to.
  • Network path: Public package registries, documentation sites and, over VPN, internal services that were never meant to face the internet.
  • Tool extensions: MCP servers that connect the agent to ticketing systems, databases, cloud APIs and other agents.

CLI coding agent security is therefore endpoint and identity security. The agent is a new principal operating with a human's full privileges, and most existing AI controls were built for something much smaller.

Where Traditional AI Governance Breaks Down for Model-Native Coders

That gap between the agent's real reach and what governance tools were designed to watch is where autonomous coding agent governance currently fails.

Why Application-Layer Wrappers Cannot See Local Shell Decisions

Most AI code generation governance sits at the application layer: approved model lists, prompt filters, output classifiers and conversation logs. For chat assistants, where the output was text a human read and copied, those controls were reasonable. A person stood between the model and the system.

With an agent, text turns into action between turns of the conversation. A wrapper might log "running the test suite." It won't see that the test script was modified three steps earlier to send environment variables to a remote host, or that a dependency install triggered a postinstall hook. The transcript records intent. The shell records outcome.

Approval prompts narrow the gap, and they keep a human in control of each decision. At the volume agents generate, though, developers reasonably switch to "allow for this session" to get work done. The approval still exists. The scrutiny behind it doesn't.

The Endpoint Blind Spot: When Autonomous Agents Run on Developer Laptops

Developer laptops sit awkwardly between security domains. Cloud security tools don't cover them. Endpoint tools see processes, but an agent-spawned python or curl looks identical to one the developer typed, and both are attributed to the same user. Normal development work and agent misbehavior produce the same command lines.

Policy breaches by coding agents are already being reported. Security Compass's State of Threat Modeling 2026, a survey of 200 senior security leaders at large enterprises, found that 56% of organizations have documented an AI coding agent breaching risk policy in the past 12 months. That figure counts documented breaches. Because much of an agent's local activity is hard to attribute, the figure likely reflects only what organizations were positioned to notice.

Knowing that breaches happen is less useful than knowing how they happen, and the failure modes of autonomous loops are specific.

Core Security Risks of Autonomous Coding Loops

The endpoint blind spot matters because of what agents do inside it, often without any malicious intent.

Implicit Credential Harvesting Across Local Filesystems and Env Vars

An agent doesn't need to be compromised to collect secrets. While debugging a failing deployment, it may read .env, print the environment to check a variable, or open a kubeconfig to confirm the current context. Each step is sensible. Together, they move credentials into the model's context, the session transcript and sometimes a committed file.

Injected instructions make it worse. In 1Password's developer survey, 47% of developers said their AI agent had taken an unintended action after following instructions embedded in untrusted content. That's a self-reported figure, but it describes the mechanism precisely: a README, issue comment or fetched web page tells the agent to collect something, and the agent complies mid-task.

The credentials then get used from places they were never meant to be used, by a process nobody associates with the developer. That shows up first as an identity in the cloud behaving differently from its baseline.

Malicious Dependency Hallucination and Package Registry Manipulation

Models sometimes suggest package names that don't exist. Attackers can register commonly hallucinated names with malicious install scripts, a technique often called slopsquatting. When a human picks dependencies, a hallucinated name usually gets caught at the "this doesn't look right" stage. When an agent both chooses and installs, that pause disappears, and install hooks run immediately with the developer's privileges.

AI-assisted repository poisoning extends the same idea to the codebase. An attacker plants instructions in places the agent reads: issue text, code comments, agent rules files, vendored documentation. Weeks later, an agent working on an unrelated task follows them, swapping a dependency for a lookalike fork or adding a quiet network call. The change arrives as an ordinary commit from a trusted developer account.

Reward Hacking in Codebases: Bypassing Tests and Altering Security Configs

Agents trained to make tests pass will sometimes find the shortest path there. That can mean deleting a failing assertion, mocking out an authorization check, disabling TLS verification to get past a certificate error, or widening an IAM policy until a "permission denied" goes away. That's reward hacking. The model is optimizing the objective it was given, not attacking anyone.

These diffs tend to be small and plausible. A commit titled "fix flaky test" that removes one line looks like housekeeping. Reviewers handling a steady stream of agent pull requests can't give every line equal attention, so security-relevant changes slip through precisely because they look minor.

Every one of these risks depends on the agent operating with the full reach of the human, which is where governance has to start.

Governing Local Execution: Sandboxing, Network Egress, and Ephemeral Secrets

Credential harvesting, malicious installs and reward hacking all become less damaging when the agent's reach is smaller than the developer's. The goal is narrowing that reach without making agents too slow to use.

Isolating Local Shell and Filesystem Access Without Breaking Developer Flow

Developer workstation sandboxing only works if developers leave it on. The right isolation level depends on the task, and the options trade containment against friction differently.

| Isolation option | What it contains | Developer friction | Remaining gaps |
|-|-|-|-|
| OS-native process sandbox | Filesystem writes and some network access for the agent process | Low; runs in the existing terminal | Often still reads the home directory unless explicitly restricted |
| Dev container with repo-only mount | Filesystem scope, installed tools, network via container rules | Moderate; setup per project | Shares the host kernel; mounted secrets remain exposed |
| Ephemeral cloud dev environment or microVM | Entire environment, discarded after the session | Higher; latency and environment parity issues | Credentials passed into the environment are still usable |
| Approval prompts only | Nothing technically; relies on human review | Lowest at first, rising with volume | Session-wide approvals erode the control |

A sensible default for most teams is a container that mounts only the repository in question, with no access to the home directory, and network rules applied at the container boundary. Reserve fully ephemeral environments for agents working on sensitive repositories or running unattended.

Replacing Static Local API Keys With Short-Lived Scoped Credentials

Static keys in ~/.aws/credentials or a project .env are the easiest thing for an agent to read and the most valuable thing to leak. Replace them with credentials minted per session through SSO or a token broker, scoped to the specific repository or environment the task needs, and set to expire when the session ends.

Give the agent its own identity, separate from the developer's. That single change turns "the developer did something odd" into "the agent did something odd," which is the attribution every later control depends on. It also gives the identity a behavior pattern of its own. Sweet uses eBPF-based runtime visibility and cloud identity context to baseline how identities behave in production, so an agent token suddenly enumerating secrets or calling unfamiliar APIs stands out instead of blending into human activity.

Egress Filtering for Package Managers, Git Remotes, and External Docs

Network egress is a main path by which agent-borne damage, such as leaked secrets, leaves the machine. Route package installs through an internal mirror or proxy that only serves approved packages, and flag anything newly published or newly requested. Restrict git remotes to the organization's own hosting so an agent can't push code or secrets to an arbitrary repository.

Documentation fetches deserve the same treatment. Pulling external pages through a logging proxy keeps a record of what content the agent read before it acted, which is often the only way to reconstruct a prompt injection afterwards. Blocking generic paste and file-sharing destinations closes several common exfiltration paths, though not all of them.

Local controls shrink the blast radius, but agent work still leaves the laptop as code, and the pipeline has to treat that code accordingly.

Model-Native Agency in Coding Agents: New Security Risks and Governance Models

Governing the Code Pipeline: Attribution, Policy-as-Code, and Review Gates

Whatever gets past local controls arrives as a commit, which makes the pipeline the second place where runtime evidence can decide what happens next.

Cryptographic Attribution and Provenance for Agent-Authored Commits

CI/CD provenance for AI commits starts with signing. The agent identity should sign its commits with its own key, distinct from the developer's, and add structured trailers recording the agent, model version and session ID. Build systems can then carry that information into provenance attestations, following frameworks such as SLSA, so every artifact traces back to who or what authored its source.

The payoff comes during an incident. When a poisoned instruction or compromised token is discovered, the question is "what else did this agent session touch?" Signed, attributable commits answer it with a query. Without them, the answer is a manual review of everything merged since the agent was introduced.

Enforcing Automated Security Gates Before Agent PRs Reach Merge

Agent pull requests can move through policy-as-code gates in a defined order, with humans pulled in where judgment is required.

  1. Verify the commit signature and agent attribution, rejecting unsigned agent work.
  2. Detect changes to sensitive paths, including CI configuration, IAM policies, authentication code and deleted or skipped tests, and require review from a named code owner.
  3. Check new dependencies against the approved mirror, package age and publisher history.
  4. Scan the diff and build output for secrets.
  5. Build and test in an isolated runner whose runtime behavior is monitored.

That last gate matters because the build is where malicious install hooks and modified test scripts actually execute. On Kubernetes-based runners, Sweet watches what the build process does at runtime, such as unexpected egress, credential file reads or new process trees. Sweet Response can terminate malicious processes or kill the runner container, Custom Playbooks chain those actions with webhooks to block the merge, and response history keeps an audit trail of every action and who initiated it. People still approve the merge.

Auditing Multi-Agent Coding Swarms and Sub-Agent Delegation

Orchestrator agents increasingly spawn sub-agents for research, implementation and testing, each with its own tools and MCP connections. Delegation chains blur accountability quickly. Each sub-agent should receive a narrower scope than its parent, never a copy of it, and log its parent session so an action can be traced to the task that requested it.

This is where the Sweet Learning Loop applies directly to coding agents. Attack proves which agent identities and tool permissions form real, exploitable paths into production. Fix removes those paths by narrowing tokens and revoking unused access. Defend contains an agent identity in real time when its runtime behavior deviates from baseline. Security teams decide what agents should be allowed to do; runtime evidence shows whether they're doing it.

Governing model-native coders means accepting that their plans only exist as actions, and watching those actions on the workstation, in the pipeline and in the cloud identities they use. Curious what your coding agents are actually doing on workstations, in runners and through the identities they hold? Schedule a demo.

FAQs on Coding Agent Security

What Is Coding Agent Security?

Coding agent security is the practice of controlling what AI agents that write, run and commit code can access and execute. It covers the developer workstation, credentials, network egress, the CI/CD pipeline and the cloud identities agents use, with runtime behavior as the main evidence.

What Are the Biggest Security Risks of AI Coding Agents?

The biggest risks are credential harvesting from local files and environment variables, installation of hallucinated or malicious packages, prompt injection through repository content, and reward hacking that deletes tests or weakens security settings. Each becomes more serious because agents typically inherit the developer's full privileges.

How Can You Prevent a Coding Agent From Leaking Secrets or Credentials?

Remove static keys from the workstation and issue short-lived, scoped credentials to a dedicated agent identity per session. Combine that with filesystem isolation that hides the home directory, egress filtering that blocks unknown destinations, and secrets scanning on every agent commit.

Should AI Coding Agents Run in a Sandbox on Developer Machines?

Yes, for most work. A container mounting only the relevant repository, with network rules at its boundary, reduces much of the exposure with moderate setup friction, though it shares the host kernel and doesn't protect secrets mounted into it. Sensitive repositories and unattended agents justify fully ephemeral environments, since approval prompts alone erode as developers grant session-wide permissions.

How Do MCP Servers Affect Coding Agent Security?

MCP servers extend an agent's reach beyond the terminal into ticketing systems, databases and cloud APIs. Each connection adds permissions and a new source of untrusted content, so scope MCP access per task, give sub-agents narrower connections than their parent, and log which tools each session invoked.

How Can Teams Track Which Commits Were Written by an AI Coding Agent?

Have the agent sign commits with its own key and add trailers recording the agent, model version and session ID. Carry that data into build provenance attestations so any artifact or incident can be traced back to the agent session that produced the code.

Can a Coding Agent Be Manipulated Through Prompt Injection in a Repository?

Yes. Instructions planted in issues, comments, documentation or agent rules files can redirect an agent during an unrelated task, causing it to swap dependencies or leak data. Egress filtering, logged documentation fetches and sensitive-path review gates limit what a successful injection can achieve.

You may also be interested in