Questions readers ask: Does sandboxing an AI agent cover prompt injection, or only limit the damage?

Sandboxing an AI agent limits the damage a successful prompt injection can cause. It does not prevent the agent from treating hostile content as a legitimate instruction. For coding-agent deployments, the full defense therefore requires two kinds of control, one governing what the agent trusts and another governing what it can execute.

What sandboxing actually does and does not do

A sandbox restricts the resources an agent’s process can touch, including file paths, network destinations, and system calls. Domain allowlists, workspace-scoped write permissions, and network egress restrictions define that boundary. Enforcement applies to actions. The sandbox constrains the environment an agent can affect after a decision is made, rather than determining how the agent reaches that decision.

The enforcement point depends on the environment. CELLMATE sandboxes browser agents at the HTTP layer because side-effecting clicks and keystrokes ultimately produce HTTP requests. Those requests express the effects of UI actions in ways that make meaningful restrictions possible. The boundary is the resulting network request.

This distinction also defines what containment leaves untouched. A sandbox does not govern the model’s reasoning process, the trust it assigns to incoming content, or its acceptance of an adversarial instruction. It has no view of the agent’s intent or the instruction channel that shaped it. An action can therefore satisfy a sandbox policy without serving the operator’s task.

Why prompt injection operates on a completely different layer

Prompt injection targets the decision before the action. It works because instructions and data travel through the same channel, without a type system that reliably separates the operator’s directives from content the agent reads. A coding agent encounters issue threads, README files, dependency changelogs, MCP tool descriptions, and error messages. Each can contain instructions that attempt to redirect the agent while appearing inside ordinary task material.

INFUSE maps five injection surface categories across realistic long-horizon workflows, namely file contents, file metadata, HTML context, email messages, and filenames. A sandbox can limit access to a file without deciding whether the agent should follow the instructions in it. By the time an injected instruction produces an action, the agent may already regard that action as legitimate.

The resulting failure is a confused deputy problem. The agent uses access it legitimately holds to serve an attacker. No credential theft or permission escalation is necessary, because the agent’s existing grants supply the capability. Individual steps can remain authorized even when their combined purpose has been redirected.

Parallax identifies a structural weakness in relying on prompts alone to prevent this outcome. Prompt guardrails and adversarial inputs share the same attention mechanism, rather than occupying architecturally separate trusted and untrusted channels. Once injection succeeds, prompt-level controls are part of the reasoning system that has been compromised. This is not evidence that sandboxing is broken. Containment was never designed to decide which instructions the agent should follow.

What the 2026 attack record shows the gap looks like in practice

The 2026 coding-agent incidents show how this distinction becomes an attack path. In Cursor CVE-2026-50548 and CVE-2026-50549, known as DuneSlide, instructions planted in content the agent read redirected its legitimate write access toward overwriting the sandbox helper binary. That overwrite disabled containment entirely. A benign user prompt was sufficient, with no further user interaction required.

Cursor patched the issue in Cursor 3.0 by restricting write access based on the agent-controlled working directory. The fix addressed the scope of containment. It did not remove the injection surface that had supplied the hostile instructions. The case therefore joins two distinct failures, an agent accepting adversarial direction and a writable resource allowing that direction to undermine the sandbox itself.

Agentjacking via Sentry MCP in June 2026 demonstrated a different outcome from the same initial trust failure. Malicious instructions in Sentry error events caused MCP-connected coding agents to execute attacker-controlled code with full developer privileges. The sandbox remained intact in this case. The attack traveled through tool output that the agent treated as trusted data, so disabling containment was unnecessary.

The GitHub MCP issue injection in May 2025 provides an earlier example of the same pattern. Hidden instructions in an issue in a public repository made an AI coding assistant take private code and put the stolen data in a public pull request. The attack followed a legitimate review-issues workflow. Across these cases, the decisive transition was from reading task material to obeying it, a transition the sandbox did not inspect.

MCP servers as the injection surface that most teams underestimate

MCP servers make that transition especially relevant to coding-agent deployments because every reachable server is an independent trust boundary. Most organizations have no inventory of which servers are active. A team cannot set permissions for a server if it does not know the server exists, who owns it, or what it does.

Tool descriptions in MCP server metadata also expose agents to attacks before they do anything the user can see. The agent reads those descriptions as guidance for using tools, making them executable instructions from its perspective. Their influence sits outside the sandbox’s action boundary. Approving a connection therefore gives no guarantee that the agent should trust every instruction it later reads through it.

MCPoison, CVE-2025-54136, illustrates the risk of treating initial approval as a durable guarantee. An attacker could get approval for an MCP configuration once, then quietly swap in malicious commands without a second prompt or approval. The MCP data-science server case exposed a different boundary failure. A caller-supplied script escaped Python’s exec() sandbox through an unrestricted __builtins__ dictionary, showing that the developer’s assumed isolation was not the boundary the attacker actually faced.

These cases differ in mechanism, but both make server discovery a prerequisite for meaningful control. Inventory makes server metadata and execution boundaries available for inspection and restriction. Shadow MCP servers turn shadow AI into a prompt-injection risk multiplier because unknown connections cannot be brought within sandbox scope, least-privilege policy, or an audit trail.

Why sandboxing still matters — as one layer, not the whole answer

Sandboxing remains a necessary blast-radius control when an agent has been redirected. Its strength depends on the permissions it encloses. A tightly scoped agent can expose only the resources it can reach, while broad grants leave more room for a malicious task to proceed inside the permitted boundary. Domain allowlists can reduce a hijacked agent’s network reach to exactly npm and GitHub. They do not establish that every permitted interaction serves the operator.

CELLMATE demonstrates the practical value of this distinction. Its HTTP-layer sandboxing blocked prompt injection attacks in the WASP benchmark with 7.25–15% latency overhead. The sandbox could prevent harmful effects even when injection succeeded at the model layer.

The trade-off is that useful agents need consequential permissions. Coding agents that commit code, call APIs, or change files must change systems outside their reasoning process. Tool permission hardening can go only so far when the work needs broad access, and sandboxing must allow the effects on outside systems that the task calls for. A permitted operation can still be the wrong operation. Tightening the boundary therefore requires an honest account of which capabilities the workflow cannot lose.

Abdelnabi and Bagdasarian argue that adversaries can construct contexts that make malicious flows appear legitimate. Loosening contextual norms enough to permit legitimate work leaves gaps that a well-constructed attack can exploit. Their conclusion frames injection as a persistent architectural risk with residual failure modes. Sandboxing remains valuable within that account, but no single filter can certify the entire workflow safe.

What the defense stack needs to cover that sandboxing leaves open

For coding-agent teams, the first task is to keep untrusted content from inheriting instruction-level authority. Input separation must be architectural rather than merely a text label, because an attacker can mimic an ordinary prefix. This reduces straightforward instruction confusion. It still leaves room for attackers to shape the context so that a malicious flow looks like part of legitimate work.

The next control narrows what the current session can do. A session that needs to read one file should not also be able to list directories, read arbitrary paths, or invoke write operations. Those restrictions reduce the capabilities available to a confused deputy. They must also change as the task evolves. Elastic least privilege adjusts scope to the current task context rather than treating the agent’s initial permissions as sufficient for every later step.

Output validation addresses the remaining gap between permission and purpose. It inspects proposed actions before execution and checks whether they fit the agent’s declared task. This is a separate check for anomalous action, regardless of whether the cause is hostile content or another failure in the reasoning process.

Parallax calls this arrangement Cognitive-Executive Separation. The reasoning system puts forward an action, and an independent validator decides whether it can run. The validator sits outside the compromised reasoning layer, so successful injection does not automatically compromise the execution gate. That separation supplies a boundary that prompt-level guardrails cannot provide on their own.

Audit must then preserve more than the final action. The audit requirements include HTTP access logs, prompt contexts, payload hashes, and reasoning traces, including chain-of-thought where available. Reconstructing a multi-step attack requires the context that connected its steps. Policy-as-code gates should also be versioned and logged as first-class artifacts so retrospective review can examine the governance logic applied at the time alongside the operations that passed through it.

How to think about deploying these controls in a real coding-agent environment

Teams should register every agent, MCP server, and skill in an organizational inventory with documented ownership and scope. This establishes which systems require controls and who is responsible for them. An undiscovered MCP server is outside the sandbox boundary, the least-privilege policy, and the audit trail.

Sandbox scope should follow the inventory at the granularity the work requires, whether per-session, per-task, or per-server. This replaces one broad perimeter with boundaries based on what agents can do and where they can connect. The inventory supplies the map for those decisions. Session permissions and pre-action validation can then cover the resources and operations each discovered agent uses, without assuming that all agents work in the same environment.

Policy rollout should begin in audit mode to establish what agents do during legitimate work. Warning mode can then describe anomalous actions in plain language where developers work, followed by approval gates for high-risk operations and, finally, blocking. Starting with blocking risks disrupting legitimate workflows before their requirements are understood. Starting with audit builds the baseline needed to scope containment and tune permissions without confusing ordinary activity with an attack.

Once enforcement is active, decisions must precede execution. A post-hoc log review cannot provide a clean intervention point for an attack whose purpose emerges across several permitted steps. An Agent Access Security Broker, or AASB, names the control layer between agents and the systems they touch. It applies discovery, pre-action policy, and audit at the fleet level, turning the layered defense into an operational model for coding agents at scale.