Severity:

HIGH RISK

(8.5)

Dynamic Code Evaluation / Sandbox Escape in n8n Python Task

CVE-2026-0863

Analyzed

Vulnerability type

Category:

Dynamic Code Evaluation / Sandbox Escape

CWE:

CWE-95, CWE-94

Impact:

Remote Code Execution and Sandbox Escape

Severity:

HIGH RISK

(8.5)

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 escape vulnerability in n8n's python-task-executor allows authenticated users to bypass Python sandbox restrictions using crafted string formatting and exception handling patterns.

When triggered through the Code block by a user with basic permissions, this flaw can enable arbitrary Python code execution on the underlying OS, potentially leading to full instance takeover in "Internal" execution mode and confined code execution in a Sidecar container in "External" execution mode.

Affected context

The vulnerability occurs within n8n workflows that use the Python Code block executed by the python-task-executor.

It is relevant when:

  • n8n is deployed with the python-task-executor enabled
  • Users with basic authenticated access can create or modify workflows using the Code block
  • The platform relies on sandboxing to constrain Python execution
  • The instance runs in:
  • Internal execution mode, where the executor has direct access to the main n8n environment, or
  • External execution mode, where the executor runs in a Sidecar container with separated privileges and filesystem

Exploit preconditions

  • Attack surface: n8n web interface / API exposing the Python Code block within workflows.
  • Required access: Authenticated n8n account with basic permissions sufficient to create or edit workflows that include Python Code.
  • Trigger point: Execution of a workflow containing malicious Python Code that leverages string formatting and exception-handling constructs to evade sandbox filters.
  • Why exploitation is possible: The sandbox's filtering and restriction logic can be circumvented by composing code dynamically through string interpolation and manipulating control flow via exceptions, allowing forbidden operations to be reconstructed and executed despite intended policy controls.

Why this happens

This issue stems from incomplete enforcement of code execution restrictions in a sandbox that evaluates dynamically generated Python code.

The python-task-executor attempts to constrain available operations but still permits patterns where:

  • Code can be constructed at runtime (e.g., via string formatting or concatenation), and
  • Exception handling and control-flow features allow reaching sensitive interpreter features or APIs that should be blocked.

This aligns with CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code, where user-influenced expressions are evaluated in a context that fails to neutralize or block dangerous constructs that can break out of the sandbox and reach the underlying operating system.

Potential impact

  • Execution of arbitrary Python code within the python-task-executor runtime.
  • Full compromise of the n8n instance, including workflow data and credentials, when running in Internal execution mode.
  • Reading, modifying, or exfiltrating data accessible to the executor process.
  • Lateral movement or pivoting to other systems reachable from the compromised environment.
  • In External execution mode, arbitrary code execution confined to the Sidecar container, potentially affecting:
  • Data and secrets mounted into that container
  • Local filesystems and services exposed to that container

General mitigation guidance

Effective mitigation focuses on strengthening sandbox boundaries and minimizing trust in user-supplied code:

  • Prefer high-level, declarative workflow nodes over generic code execution wherever possible, reducing the need for user-provided Python.
  • Harden the python-task-executor sandbox by:
  • Restricting or removing dynamic evaluation features entirely (e.g., disallowing eval-style behavior and reflective imports).
  • Enforcing strict whitelists of allowed modules, attributes, and builtins rather than attempting to blacklist dangerous ones.
  • Treating any user-controllable string interpolation or code construction as untrusted and disallowing it in sandboxed contexts.
  • Isolate execution environments using process and container isolation, applying least-privilege OS-level policies (e.g., limited filesystem access, restricted networking, reduced OS capabilities).
  • Limit which user roles are allowed to run arbitrary code blocks, and prefer separate, more trusted accounts for administrative automation tasks.
  • Centralize configuration so that sandbox settings default to the most restrictive posture and must be explicitly relaxed only for controlled environments.

How teams detect issues like this

Organizations can detect and monitor for this class of issue through:

  • Static analysis and code scanning of the python-task-executor:
  • Identify any remaining dynamic evaluation primitives (e.g., generic exec, eval, or similar mechanisms).
  • Flag patterns that allow user input to influence code strings, especially in combination with try/except or other control flow designed to bypass filters.
  • Security-focused code review of sandbox logic:
  • Verify that restrictions are enforced at the interpreter boundary, not just via superficial string checks.
  • Examine exception handling paths to ensure they cannot be abused to reintroduce dangerous functionality.
  • Runtime monitoring and logging:
  • Capture detailed logs of Code block executions, including which workflows and users initiated them.
  • Alert on anomalous patterns such as:
  • Unusual imports or OS-level interactions from Code blocks.
  • Repeated failures followed by successful executions that indicate probing for bypasses.
  • Policy enforcement in CI/CD:
  • Integrate SAST or linters into the development pipeline to flag reintroduction of dynamic evaluation or overly permissive sandbox configurations.

Sources

SourceLink
github.comgithub.com/n8n-io/n8n/commit/b73a4283cb14e0f27ce19692326f362c7bf3da02
research.jfrog.comresearch.jfrog.com/vulnerabilities/n8n-python-runner-sandbox-escape-jfsa-2026-001651077/
smartkeyss.comsmartkeyss.com/post/cve-2026-0863-python-sandbox-escape-in-n8n-via-exception-formatting-and-implicit-code-execution

Frequently asked

questions

It can be exploited remotely if the n8n instance is exposed and an attacker has valid credentials with permissions to create or edit workflows containing Python Code. The vulnerability does not itself bypass authentication; it elevates what an authenticated user can do.

An attacker needs an authenticated n8n account with basic permissions sufficient to define or modify a workflow that uses the Python Code block executed by the python-task-executor. No special administrator privileges are required beyond that workflow authoring capability.

The most robust fix is to redesign the sandbox so that user-provided Python cannot dynamically reconstruct restricted operations—this typically means removing or heavily constraining dynamic evaluation features, enforcing strict whitelists on accessible APIs, and verifying that exception paths cannot re-enable blocked functionality. Where possible, replace generic "run arbitrary code" nodes with narrowly scoped, parameterized operations.

Avoid exposing general-purpose interpreters to end users when practical, and when they are necessary, treat them as highly sensitive attack surfaces. Apply secure-by-default sandboxing with strong whitelists, validate sandbox behavior with targeted security testing and fuzzing, enforce least privilege at the OS/container level, and integrate static and manual reviews focused specifically on dynamic code evaluation patterns.

Find out what's already
exploitable in your codebase.