Critical Security Controls for Governing AI Coding Agents | Endor Labs

Critical Security Controls for Governing AI Coding Agents

Six places to enforce AI coding agent governance on the developer's machine, and why in-agent hooks are the one deterministic control between intent and action.

Written by

Robert Haynes

Published on

July 29, 2026

Updated on

July 30, 2026

Introduction

Let’s start with an obvious statement: developers are using AI coding assistants to create the code for the applications and features they design. So what? Well, these agents read more files, touch more of the filesystem, and produce larger commits than the developer would alone, and all of it runs on a laptop with that developer's credentials loaded.

The agentic development stack assembled itself on those laptops over about eighteen months, without a procurement cycle, a threat model, or a control plan. This has, somewhat predictably, created an attack surface that adversaries have leveraged to steal credentials and secrets, which are then used to spread malicious code, which then repeats the cycle.

The appeal of a developer’s workstation is easy to understand: a combination of powerful desktop agents, a pattern of performing software installs, and a credential-rich environment make this a prime target for bad actors.

The good news is that protecting endpoints is a mature cybersecurity practice. The bad news is that most of these controls are inadequate to defend against these specific attack types (although still arguably necessary). In addition, some new tools like Model Context Protocol (MCP) gateways, while not without value, are less useful in protecting workstations than you might think.

What we are actually defending against

An AI coding agent is a process on a developer's machine with a shell, filesystem access, network access, and the developer's credentials. It reads your repository and runs commands. That is the job, and the risk follows from the capability. An agent that can run npm install can also read .env and POST it somewhere. An agent that can edit Terraform can run terraform destroy. Because the interface is natural language, anyone who can plant a sentence where the agent will read it, in a README, an issue comment, or a package description, can try to talk it into doing something it should not. The action then runs at machine speed with the developer's own permissions, so it looks legitimate on the way past.

In addition, AI coding agents can and will install third-party libraries in order to test the software they create, exposing workstations to the risk of malware embedded in package install scripts.

This is where a vendor likes to position a ‘buy this, and it solves everything’ product, but any seasoned security professional knows that’s bunk. Good protection requires defense in depth, which rarely comes from one tool alone (although your friendly vendors are always working hard to get there).

Six places to enforce control

There are six places we can enforce controls on AI coding agents:

  1. EDR and XDR
  2. Sandboxes and containers
  3. AI gateway and MCP gateways
  4. In-agent hooks
  5. Package firewalls
  6. Secrets scanning and pull request controls

Each of these sees a genuinely different slice of the agent loop.

Approach Control point Blocks before execution Main blind spot Developer cost
EDR / XDR Operating system No Intent behind a command Build slowdowns, exclusion lists
Sandbox / container Process boundary Yes, for reach. Not for intent Anything permitted inside the boundary Broken installs, network friction
AI / MCP gateway Network path to model Prompts and model access only All local shell and file activity Low, until an agent bypasses it
In-agent hooks Between intent and action Yes Agents with no hook support Low. May need more developer approval during a task
Package firewall Package manager to registry Yes Non-package code paths Low. Package firewall is invisible until it blocks
Secrets scanning / PR review Commit and review No Anything not committed Low

Why hooks are the right place for policy

Hooks are not a new idea, which works in their favor. Git has them. Pre-commit has them. Kubernetes admission webhooks are the same pattern: the platform exposes a well-defined point in its lifecycle, hands control to a script the operator owns, and acts on the answer. Applied to a coding agent, the model decides what it wants to do and the hook decides whether it gets to.

That separation buys four things.

Our differentiation is coverage on one policy plane. Endor Labs wires endorctl ai-audit to Claude Code and Cursor events, and ships 29 default policies across shell commands, sensitive file access, MCP tool calls, prompts, and skills, plus custom regex rules. The same platform runs the package firewall, so "block malware before it reaches the workstation" and "block the agent from reading .pem files" are two policies in one console rather than two products with two audit trails. It needs no per-IDE plugin either, which matters when the honest answer to "which agents are your developers using?" is "at least four."

Where would hooks have helped?

Incident EDR / XDR Sandbox AI / MCP gateway In-agent hooks Package firewall Secrets / PR review
Nx "s1ngularity" (Aug 2025)Postinstall script invokes the local AI CLI to harvest SSH keys and .env files Partial No No Yes Yes No
Amazon Q extension injection (Jul 2025)Injected instruction to wipe the host and delete AWS resources, shipped in a release Partial Partial No Yes No No
GitHub MCP toxic flow (May 2025)Planted issue makes the agent publish private repo contents to a public PR No No Partial Yes N/A Partial
Replit production DB deletion (Jul 2025)Agent dropped a live database during an explicit code freeze No No No Yes, if the harness exposed hooks N/A No
Cursor MCPoison, CVE-2025-54136 (Aug 2025)Approved mcp.json entry silently swapped after approval Partial Partial No Yes No Partial
postmark-mcp backdoor (Sep 2025)Rogue MCP server BCCs every outbound email to the author No No No Yes Yes No
Shai-Hulud (Sep 2025, 2.0 in Nov)Self-replicating npm worm scans for and exfiltrates developer credentials Partial Partial No No Yes Partial
Rules File Backdoor (Mar 2025)Invisible unicode in a shared rules file makes the agent emit backdoored code No No No Partial No Partial

What we would advise

Layer, and put hooks at the center. Sandbox the agent so a mistake has a small radius. Put policy at the hook layer so the dangerous action never starts. Put the package firewall in front of the registry so the dependency tree stays clean. Keep EDR underneath, because it covers what hooks cannot see: agents with no hook support, the developer who removed their config, the process that was never an agent at all. Hooks work on cooperative software, so treat the hook configuration as a protected asset.

If you are early, start with logging only. A hook that records every prompt, command, and file read will tell you more in a fortnight than any survey will, and adding enforcement afterward is a config change rather than a re-architecture.

Governance is what lets you say yes to these tools. A security team with deterministic policy and a real audit trail can approve a coding agent on the same terms it approves anything else, which is a considerably better position than debating whether to allow the tool your developers have already installed.

You can see how AI Coding Agent Governance works, read the technical walkthrough of the hooks integration, or book a demo if you would rather see it against your own policies.

What's next?

When you're ready to take the next step in securing your software supply chain, here are 3 ways Endor Labs can help:

[Explore the Secure Code Prompt Library

Download 40+ AI prompts for secure vibe coding.](/content/lp/secure-ai-code-prompt-library/index.html) [Take a tour of Endor Labs

Explore Endor Labs with a self-guided platform tour.](/content/platform-tour/index.html) [Book a Demo

See Endor Labs in action with a custom walkthrough.](/content/demo-request/index.html)