Skip to content

All posts

AIKubernetes

AI agent security guide: controls for coding agents, MCP and Kubernetes agents

Ritesh Patel

AI: AI agent security guide: controls for coding agents, MCP and Kubernetes agents

AI agent security comes down to three enforcement points: the coding agent’s own settings on each developer machine, the MCP servers and gateways that carry tool calls, and Kubernetes admission and RBAC for agents that run as workloads. Each threat has one primary control and one enforcement point.

Threat, control and enforcement point

The table lists the threats that matter for coding agents, MCP and Kubernetes agents. The control is the mechanism that addresses the threat. The last column is the layer that enforces it, which decides who can change it and where it stops.

Threat Primary control Where enforced Limit the docs state
Instructions hidden in content the agent reads Permission prompts, deny rules, sandbox, VM for untrusted work Developer machine (agent settings) No system is immune to all attacks
Destructive shell commands Bash deny rules plus a PreToolUse hook Agent settings, managed where deployed A Bash rule does not match /bin/rm or sh -c forms
Secrets read from disk Read deny rules and sandbox filesystem limits Agent settings and OS sandbox The sandbox covers shell commands, not file tools
Unreviewed MCP servers Managed MCP configuration and allowlist by URL or command Managed settings, MCP client Anthropic does not security-audit MCP servers
Over-broad MCP tool actions Per-tool rules and tool risk classes Client rules and MCP server Tool hints are not guarantees
Calls nobody can attribute Per-developer credentials and call logs Gateway or identity provider Local transcripts can be deleted
Agent pods that are too privileged Admission policy and Pod Security levels Kubernetes admission Admission intercepts writes; reads bypass it
Agent service accounts with too much access Least-privilege RBAC roles Kubernetes API authorization RBAC has no deny rules
Runaway spend Per-user and per-session budgets Gateway Applies only to traffic routed through the gateway

Coding agents on the developer machine

A coding agent needs four controls on the machine: permission rules, a sandbox for shell commands, hooks for the call forms rules miss, and managed settings so developers cannot remove the rest. The risks and controls post explains each one against the Claude Code docs. Start with the destructive commands post for deny rules and hooks, and the secrets post for read rules. The sandbox how-to covers OS-level limits. For prompt injection specifically, read the prompt injection defense post, since no single layer stops it.

Order of enforcement

Knowing which layer wins avoids a false sense of safety. Claude Code evaluates deny, then ask, then allow. A hook that exits with code 2 blocks a call before permission rules run, so the block holds even when an allow rule would permit it. A hook cannot remove a deny rule, though. The managed settings post covers how to deploy the rules centrally so a developer’s project file cannot override them.

{
  "permissions": {
    "deny": ["Bash(rm *)", "Bash(curl *)"]
  }
}

The rule above blocks rm -rf build/, but not /bin/rm -rf build/ or bash -c 'rm -rf build/'. Those forms need a hook or the sandbox.

MCP servers and tools

MCP adds a second trust boundary. Each server is a program or remote service that exposes tools to the agent, so approval has to happen per server and per tool. Start with the MCP security checklist, which orders the work from inventory to logging. The allowlist post covers the match rules for URLs and commands. The MCP tools specification says servers MUST validate tool inputs, implement access controls, rate limit calls and sanitize outputs. Clients SHOULD prompt for sensitive operations and log tool usage. Those are two sets of duties, and a gap in either one leaves the call exposed.

Classify tools before you write rules. The tool risk classes post uses the readOnlyHint and destructiveHint annotations, and it says to set each class yourself because the spec treats those hints as untrusted unless the server is trusted. For per-call decisions, see tool-level authorization, and for the difference between a gateway and policy at the call, see MCP gateway vs policy enforcement.

Agent identity and privilege

An agent should act under an identity you can revoke, and that identity should hold only the access its job needs. A shared API key gives no owner and no way to tell agents apart. The agent identity explainer defines the terms, and the identity in Kubernetes post shows how to give each agent a service account. Kubernetes RBAC grants permissions by role and binding, and it has no deny rules, so the safe default is an empty role and an explicit grant. The RBAC post walks through a role per agent, and the over-privileged agents post shows how to find the grants that have grown too wide.

Kubernetes agents

Kubernetes agents need two checks. Admission control decides what an agent’s pods may look like before they start. Kubernetes runs admission controllers after authentication and authorization and before the object is persisted, and a rejection stops the request. Kyverno policies apply that check to agent workloads; the Kyverno policies for AI agents post lists the rules. The admission versus runtime post explains why admission cannot see the agent’s tool calls, which happen after the pod starts. Run each agent in a hardened pod with sandboxed agent pods, and check the Pod Security Admission levels post for the baseline.

Audit and incident response

A control you cannot trace is hard to prove. Record which agent ran which command or tool, for whom, and what the policy decided. The coding agent audit post covers the developer side, the MCP tool call audit post covers the call side, and the Kubernetes audit post covers the cluster side. When something goes wrong, the AI agent incident post gives the order of steps.

Mapping controls to risk frameworks

Auditors often ask for controls mapped to a framework rather than a list of tools. The OWASP LLM Top 10 mapping lists each risk with the agent control that limits it, which helps when you present the stack to a risk committee. Use the mapping as a starting point and check each row against the controls you have actually deployed.

Enforcing this with AIControls

The controls above live in three places: the developer machine, the MCP path and the cluster. AIControls covers the parts that need one central point, and its confirmed capabilities are routing Claude Code through a gateway, issuing per-user tokens, setting per-user and per-session cost limits, and holding or redacting PII before it reaches a model. The AIControls coding agents page shows how these fit with the machine settings, and the AI agent governance solution page describes the Kubernetes side. The AIControls platform page covers the product overall.

Sources

Frequently asked questions

What are AI coding agent security controls?

They are the settings and checks that decide what a coding agent such as Claude Code may read, run and send. The main ones are permission rules, a sandbox for shell commands, PreToolUse hooks, managed settings and per-developer credentials. Each stops some risks and none stops all of them, so pair them and check what each one does not cover.

What are AI agent governance platforms?

They sit between agents and the tools, models and data they use. A governance platform records who or what the agent acts for, checks each call against written policy, and logs the decision. Some work at a gateway in front of the model and tool servers, others at Kubernetes admission. Pick one that covers the surfaces your agents actually use.

How do you enforce policies on AI agents in Kubernetes?

Use the Kubernetes admission path for what an agent's pods may be, and RBAC for what its service account may call. Admission controllers run after authentication and authorization and before an object is stored, so a policy engine such as Kyverno can reject a non-compliant agent pod. Runtime calls made by the agent through MCP or model APIs need a separate enforcement point.

Can a hook override a deny rule in Claude Code?

No. Claude Code evaluates deny and ask rules whatever a PreToolUse hook returns, so a matching deny rule blocks the call even when the hook answers allow. A hook can add a block. An exit code 2 from a hook blocks the call before permission rules are checked, but it does not remove a deny rule.

Why is an MCP server name not a security control?

A name is a label that any user can set, so two servers can share one and a server can claim a trusted name. Approve servers by the exact URL or command they run from, and record the owner and the tools they expose. The MCP tools specification also says there should be a human who can deny each tool invocation.

Ritesh Patel, Founder & VP Product, Nirmata

Ritesh Patel is a founder of Nirmata and leads its products. He writes about governing AI coding agents, MCP security and Kubernetes policy as code.

LinkedIn

Govern AI agents with AIControlsControl what AI agents do, and prove it.
Share

Stay up-to-date with the latest in AI, governance, and infrastructure

Subscribe to our free monthly newsletter to get industry news, DevOps tips, and articles right to your inbox on Kyverno, containerization, Kubernetes deployment & management and more.