Summary
A sandbox bypass vulnerability in the Cursor AI code editor allows an agent to set its working directory to arbitrary writable locations outside the intended workspace. Under specific conditions, this enables writing files anywhere the user can, including helper binaries used to enforce sandboxing.
If a malicious or compromised agent abuses this flaw, it can achieve non-sandboxed remote code execution under the user's privileges without additional interaction beyond an apparently benign prompt.
Affected context
This vulnerability occurs in Cursor versions prior to 3.0 when AI agents are allowed to execute terminal commands inside a filesystem sandbox. The sandbox is intended to restrict write access to the agent's working directory and workspace, but the logic that validates and constrains the working_directory parameter is flawed. When the agent can influence this parameter, the sandbox may include writable paths outside the intended project directory, extending the agent's write capabilities to sensitive locations on the user's system.
Exploit preconditions
- Attack surface: AI agent command execution within Cursor's integrated terminal sandbox.
- Required access: Ability to control or influence the agent that issues terminal commands, such as a malicious prompt, compromised model, or injected tool configuration.
- Trigger point: The agent sets the working_directory parameter to a path outside the allowed workspace (e.g., a directory containing Cursor helper binaries or system scripts).
- Why exploitation is possible: The sandbox implementation does not robustly validate or normalize the working_directory path against a strict workspace root and trust boundary, permitting path traversal or arbitrary directory selection that expands write access beyond the original sandbox.
Why this happens
The root cause lies in improper handling and validation of file system paths used to define the sandbox's working directory, aligning with CWE-22 (Improper Limitation of a Pathname to a Restricted Directory). Instead of enforcing that working_directory remains confined to a trusted workspace root, the implementation allows agent-controlled values to effectively redefine the sandbox scope. This design error means untrusted data (the working_directory parameter) is treated as a trusted configuration for sandbox boundaries, permitting writes to directories that should never be reachable. Conceptually, it is a combination of path traversal and sandbox boundary misconfiguration where a user-controlled path escapes the intended restricted directory tree.
Potential impact
- Malicious agents may write arbitrary files anywhere under the user's OS-level privileges.
- Attackers could overwrite Cursor sandbox helper binaries or scripts so subsequent commands execute fully unsandboxed.
- Remote code execution can occur when overwritten files are later invoked or loaded by Cursor or other applications.
- Local persistence or backdoor installation may be possible by modifying startup scripts or configuration files.
- Data integrity issues could arise from altering project files, editor configuration, or other user documents.
General mitigation guidance
Effective mitigation revolves around tightening path handling and sandbox boundary enforcement. Common defensive patterns include:
- Treat all path-like inputs from agents, prompts, or external tools as untrusted and subject to strict validation and normalization.
- Enforce that working_directory must always be a descendant of a predefined workspace root, rejecting any value that escapes this tree.
- Implement canonical path resolution and explicit checks to prevent path traversal (e.g., use resolved absolute paths and compare against allowed prefixes).
- Design the sandbox so that its scope cannot be expanded by untrusted configuration and avoid granting write access to directories that contain security-critical executables or helpers.
- Apply least-privilege principles to helper components and avoid storing sensitive binaries or scripts in locations writable by untrusted processes.
How teams detect issues like this
Detection typically focuses on reviewing both code and runtime behavior for path handling around sandbox boundaries:
- Use static analysis or custom linters to flag code paths where untrusted input influences directory selection, sandbox configuration, or path concatenation without normalization.
- During code review, pay attention to any logic that constructs working directories, checks path ownership, or defines sandbox root paths, looking for missing validations or weak comparisons.
- Enforce security policies that require explicit workspace-root checks for any feature that accepts user- or agent-specified paths.
- Instrument logging around agent command execution, recording requested working_directory values and detecting unexpected directories or failed validation attempts.
- Optional automated tools can be configured to scan for CWE-22 patterns such as use of raw path joins, absence of canonicalization, or failure to constrain paths to a fixed base directory.

