/

CVE-2026-50548

Severity:

CRITICAL RISK

(9.8)

Path Traversal (CWE-22) in Cursor AI Agent Sandbox

CVE-2026-50548

Analyzed

Vulnerability type

Category:

Path Traversal / Sandbox Escape

CWE:

CWE-22

Impact:

Sandbox Escape Leading to Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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.

Sources

SourceLink
github.comgithub.com/cursor/cursor/security/advisories/GHSA-3p48-7v9f-v5cw

Frequently asked

questions

Exploitation depends on an attacker's ability to control the AI agent or its prompts. If they can cause the agent to issue terminal commands with a malicious working_directory, they may be able to escape the sandbox and write files anywhere the user can.

Not necessarily. The attack can originate from remote input, such as a prompt or external content that influences the agent's behavior. Once the agent runs commands with a crafted working_directory, file writes occur under the local user's privileges, effectively enabling remote code execution.

The safest pattern is to strictly constrain path parameters to a trusted root directory, resolving paths to their canonical form and rejecting any value that escapes the intended workspace. Additionally, sandbox boundaries should never be adjustable by untrusted inputs, and sensitive helper binaries should live outside writable locations.

Future designs should treat all agent-controlled configuration as untrusted, apply rigorous path validation and normalization, and define immutable sandbox roots enforced by central policy. Combining these with comprehensive code review, automated checks for CWE-22 patterns, and least-privilege filesystem layout greatly reduces the risk of sandbox escapes.

Find out what's already
exploitable in your codebase.