Summary
When the Cursor Agent runs in Auto-Run Mode with Allowlist mode enabled, it can execute certain shell built-ins without those commands appearing in the allowlist or requiring user approval.
Through direct or indirect prompt injection, an attacker may cause the agent to set, modify, or remove environment variables that influence trusted commands, leading to severe command execution and workflow compromise risks.
Affected context
The vulnerability manifests in Cursor installations where:
- The Cursor Agent is enabled and running in Auto-Run Mode
- Allowlist mode is configured to limit what shell commands the agent may execute
- Users allow the agent to interact with a system shell as part of its coding and tooling workflows
In this configuration, some shell built-in commands are not properly governed by the allowlist and can be run without explicit user consent. If the agent is exposed to untrusted or partially trusted prompts (e.g., from code, documentation, web content, or collaborative sessions), those prompts can influence the agent's shell usage in unexpected ways.
Exploit preconditions
- Attack surface: The Cursor Agent's natural-language interface and any channels that can inject text into its context (project files, comments, external content, shared sessions).
- Required access: Ability to provide or influence prompts that the agent processes, directly (e.g., chatting with the agent) or indirectly (e.g., malicious code comments, README, or external resources that the agent reads).
- Execution context: The agent must be running in Auto-Run Mode with Allowlist mode enabled, and configured to interact with a shell on the user's machine.
- Trigger point: The agent receives adversarial instructions that cause it to invoke shell built-ins that are not enforced by the allowlist, specifically to set, alter, or clear environment variables.
- Why exploitation is possible: The allowlist enforcement does not fully cover shell built-ins, so environment-mutating commands can execute silently. Trusted tools and commands later launched in the same environment implicitly inherit attacker-controlled variables, allowing behavior changes without additional prompts or consent.
Why this happens
The core issue is incomplete mediation of shell command execution when controlled by an AI agent. The allowlist mechanism is designed to constrain which shell commands can run automatically, but it does not robustly handle shell built-ins and their ability to mutate the process environment.
From a vulnerability-class perspective, this aligns with CWE-15: External Control of System or Configuration Setting, because untrusted prompt content can indirectly control environment variables that affect how trusted commands behave. The problem is compounded by the AI agent's high level of automation (Auto-Run Mode) and the assumption that the allowlist fully defines the execution boundary, while in reality shell built-ins slip past that boundary and can silently poison the environment. Related CWEs (CWE-74/77/78/94/269) are implicated because the environment manipulation can steer how commands are constructed, executed, or which privileges and behaviors they effectively adopt.
Potential impact
- Environment poisoning that changes how trusted build, test, or deployment tools behave
- Indirect execution of malicious or unintended commands when legitimate scripts rely on altered environment variables
- Tampering with compiler, interpreter, or package-manager behavior (e.g., changing search paths or flags) to introduce backdoors or supply-chain modifications
- Modification of security-relevant variables, potentially weakening sandboxing or path restrictions
- Persistence of malicious behavior within the session by keeping poisoned environment variables active across multiple command invocations
- Data loss, corruption, or exfiltration via trusted tools operating under attacker-controlled environment settings
General mitigation guidance
Effective mitigation centers on narrowing the trust boundary of AI-driven shell access and treating environment state as a high-risk asset:
- Prefer designs where AI agents interact with sandboxed shells or ephemeral environments instead of the user's primary development shell.
- Enforce strict mediation of all shell interactions, including built-ins, by routing them through a single control layer that applies allowlists and policy checks uniformly.
- Treat environment-altering operations (e.g., changing PATH, LD_LIBRARY_PATH, language-specific PATH/FLAGS, credentials, and proxy settings) as privileged actions that require explicit, high-friction user consent.
- Apply principle of least privilege to the shell environment presented to the agent—avoid exposing sensitive environment variables, tokens, or security-critical configuration to agent-controlled processes.
- Introduce configuration options to completely disable environment mutation by AI agents unless specifically required.
- Encourage workflows where generated shell commands are reviewed by the user before execution when working with untrusted codebases, documents, or collaborators.
How teams detect issues like this
Detection strategies typically revolve around monitoring AI-agent shell behavior and validating environment integrity:
- Implement logging of all agent-triggered shell commands, including built-ins, and flag commands that mutate the environment (e.g., export, set, alias, function definitions).
- Use host-based monitoring or instrumentation to track environment changes in shells spawned by development tools, and alert when unexpected or high-risk variables are modified.
- Apply static analysis or policy-as-code checks on any "tooling integration layer" that wires the agent to the shell, ensuring that:
- All execution paths go through the same allowlist and policy enforcement
- Built-in commands and environment-mutating operations are explicitly handled
- Incorporate security-focused code review for AI integration features, paying particular attention to:
- Trust boundaries around prompt content
- Any path where untrusted input can influence command construction or environment state
- Optionally, leverage automated review tools or CI policies that scan for direct shell access from AI components and require additional approval for environment-related behavior.

