The first time it happened to me, the code looked harmless. An agent was asked to “summarize this CSV and chart the totals.” The model wrote a few lines of Python, the executor ran them and a chart came back. Fine. Except, buried in the same task, on a later run with a poisoned input file, the generated code did something else first: It walked os.environ, then tried to open a TCP connection to 169.254.169.254 — the cloud metadata endpoint. It was reaching for instance credentials before it ever touched the CSV.
Nobody jailbroke the model in the dramatic, screenshot-worthy way. A string in untrusted data told the model what to do, the model wrote code to do it and the executor — running with the agent’s privileges — happily complied. That is the whole attack. The model is not the breach. The model is the social engineer. The breach is the process you let it drive.
The Code An Agent Ran That It Shouldn’t Have
Here is the framing security teams keep missing. An agent with a code interpreter or a tool-call loop is an unauthenticated, internet-influenced user with a remote code-execution primitive. Whatever that process can read, open or reach, the attacker can too, by writing instructions into any byte the model will eventually see.
OWASP’s 2025 Top 10 for LLM Applications puts prompt injection at number one and adds excessive agency as its own entry, broken into three root causes: Too much functionality, too many permissions and too much autonomy. Read those again as a security person, not an ML person. Those are not alignment problems. They are privilege problems. A jailbroken prompt is inert if the process it steers cannot open a socket, read a secret or fork a shell.
So, the defensive question is not “how do I make the model behave?” It’s “when the model misbehaves — and it will — what can the body it controls actually touch?” You answer that with isolation and least privilege, the same way you’d contain any untrusted workload. Not with a more polite system prompt.
A Container is Not a Security Boundary
This is the misconception that gets teams owned: A Docker container feels like a sandbox, so people run agent-generated code in one and call it contained.
A standard container is a process-isolation feature, not a security boundary. Containers on the same host share one Linux kernel. Namespaces and cgroups partition the view, but the syscalls all land on the same kernel. One kernel privilege-escalation bug — and there is a steady supply — and the ‘sandbox’ is a host shell. You are betting the integrity of your node, and everything else scheduled on it, on the model never generating an exploit and the kernel never having a bug. Both are bad bets when the workload is literally untrusted code an internet-controlled string can author.
The fix is a real isolation layer under the container. There are three mature options, and you don’t need to invent any of them.
gVisor intercepts the workload’s syscalls in a userspace application kernel (runsc) instead of passing them straight to the host kernel, shrinking the attack surface a hostile process can reach. Firecracker boots a lightweight microVM per workload with hardware virtualization, the same technology under AWS Lambda and Fargate. Kata Containers runs ordinary OCI containers inside a lightweight VM so you keep your existing images and tooling while getting VM-grade isolation. Different trade-offs, same principle: The agent’s blast radius stops at a boundary the host kernel does not share.
The Isolation Stack in YAML
Isolation is the floor, not the ceiling. Stack the cheap, boring controls on top: A tight syscall filter, zero capabilities, no service-account token and an egress policy that denies by default. Here is a hardened Kubernetes pod for an agent code-executor, vendor-neutral, with a default-deny egress policy beside it.
apiVersion: v1
kind: Pod
metadata:{name: agent-exec,namespace: agents,labels:{app: agent-exec }}
spec:
runtimeClassName: gvisor # run under runsc (userspace kernel), not the host kernel
automountServiceAccountToken:false # no Kubernetes API token in the sandbox
securityContext:{runAsNonRoot:true,seccompProfile:{type: RuntimeDefault }}
containers:
–name: exec
image: registry.internal/agent-exec@sha256:<pin>
securityContext:{allowPrivilegeEscalation:false,readOnlyRootFilesystem:true,capabilities:{drop:[“ALL”]}}
resources:{limits:{cpu:“1”,memory: 512Mi }} # cap runaway / unbounded consumption
—
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:{name: deny-egress,namespace: agents }
spec:
podSelector:{matchLabels:{app: agent-exec }}
policyTypes:[“Egress”]
egress:[] # empty allow-list blocks ALL egress, DNS included
Two gotchas that will burn you in production: First, a Kubernetes NetworkPolicy does nothing unless your CNI enforces it — the object applies cleanly and silently protects nothing on a cluster whose network plugin ignores it. Second, that empty egress: [] is genuinely default-deny, which means it also blocks DNS. Any agent that resolves a hostname will hang. You have to add a narrow rule allowing UDP and TCP 53 to kube-dns and then allow only the specific destinations the task actually needs. That is the point: The executor reaches the metadata endpoint over exactly nothing, because you never put it on the allow-list.
The Tool and MCP Attack Surface is Real, not Theoretical
Code execution is the obvious door. Tool calls are the quiet one, and the model context protocol (MCP)-made tool calls are a standard interface — which means a standard attack surface.
Treat an MCP server like what it is: A network service holding delegated authority, whose client is a non-deterministic model that will follow instructions hidden in any byte the server returns. Three concrete attack classes the security community has already demonstrated:
Tool Poisoning: Malicious instructions embedded in a tool’s description — invisible to the human approving it, fully visible to the model. A benign-looking add(a, b) whose description quietly tells the model to read local secrets and pass them out through the tool’s parameters. Approval theater does not help when the payload rides in the metadata you approved.
Prompt Injection via Tool Output: Any data a tool returns is an injection vector. A crafted ticket, a planted file, a hostile web page fetched mid-task — the model trusts convincing tokens regardless of their origin. Combine private-data access, untrusted content and an outbound channel and you have handed it everything an exfiltration needs.
Confused Deputy and Token Passthrough: If your MCP server forwards the token it received to an upstream API, it lends its caller the upstream’s authority. The spec is explicit: A server must validate that a token was issued for it by audience and must not pass tokens through. Scope tokens per tool, bind them to an audience and keep them short-lived. A read-only, 10-minute token is a small blast radius. org:admin is the whole org.
Watch the Runtime, Something Will Get Through
Assume a control fails. Put eyes inside the boundary. eBPF tooling watches syscalls in the kernel: Falco observes and alerts, Tetragon can enforce in-kernel and kill a process or drop a connection in real-time. Run detection for visibility and enforcement where you need to stop an action mid-flight and wire both into the same alerting path as the rest of your security telemetry. A process in an agent sandbox touching the metadata IP, spawning an unexpected shell or reading a path it has no business reading is a high-signal event — if anyone is looking.
The Takeaway
Stop spending your security budget trying to talk the model out of misbehaving and start spending it on what the misbehaving process can reach. Run agent code in real isolation, not a shared-kernel container; drop capabilities, kill the token, deny egress by default; treat every tool and MCP server as delegated authority with a least-privilege, audience-bound token; watch the runtime for the day a control fails. The agent will try something it shouldn’t. Decide now whether that ends at a sandbox wall or at your metadata endpoint.

