/

CVE-2026-76825

Severity:

HIGH RISK

(8.4)

Sandbox Escape (CWE-693) in RestrictedPython Formatter

CVE-2026-76825

Deferred

Vulnerability type

Category:

Sandbox Escape

CWE:

CWE-200, CWE-470, CWE-680, CWE-693

Impact:

Host-Level Code Execution

Severity:

HIGH RISK

(8.4)

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

RestrictedPython could allow restricted code to escape its sandbox when a custom import policy or globals exposed the standard library string module, string.Formatter, or related formatter objects. Because formatter methods performed attribute and item traversal outside RestrictedPython's safer access controls, an attacker may reach host functions, builtins, file access, or code execution primitives.

Affected context

The vulnerability occurs in RestrictedPython environments that expose the standard library string module, a string.Formatter class or instance, or a Formatter subclass to restricted code. It requires a deployment configuration in which custom import policies or globals make these live formatter objects available, allowing their internal traversal behavior to bypass the sandbox's usual attribute-access protections.

Exploit preconditions

  • Attack surface: Restricted Python code executed within a host application
  • Required access: Ability to submit or influence code processed by the RestrictedPython environment
  • Configuration requirement: A custom import policy or global namespace exposes the standard library string module or a Formatter-related object
  • Trigger point: Invocation of formatter functionality that performs field, attribute, or item traversal
  • Why exploitation is possible: Relevant formatter methods access objects internally without routing traversal through RestrictedPython's safer attribute-access controls

Why this happens

The underlying issue is a protection-mechanism failure caused by trusted formatter objects crossing the sandbox boundary. The format, get_field, get_value, and vformat methods performed attribute and item traversal internally, bypassing the restricted access mediation expected by the sandbox. This behavior maps primarily to CWE-693: Protection Mechanism Failure, with related concerns involving unsafe reflection, unintended information exposure, and uncontrolled resource or object access.

Potential impact

  • Restricted code may access host functions or builtins
  • An attacker could read files or other sensitive host data
  • Host-side code execution may occur
  • Application confidentiality, integrity, and availability could be affected
  • A compromised process could be used for further local or network activity

General mitigation guidance

Mitigation generally focuses on preserving a strict trust boundary between restricted code and host objects.

Common defensive patterns include:

  • Avoiding exposure of the standard library string module and Formatter-related objects to restricted code
  • Applying explicit allowlists to imported modules, globals, classes, and object capabilities
  • Routing all attribute and item traversal through sandbox-aware access controls
  • Prefering narrowly scoped data-only interfaces over live host objects
  • Running sandboxed workloads with least privilege, isolation, and restricted filesystem and network access
  • Treating sandboxed code as potentially hostile and limiting the value of any host capabilities it can reach

How teams detect issues like this

Detection can include:

  • Static analysis for exposure of string.Formatter, Formatter instances, or Formatter subclasses in restricted globals
  • Code review checks for custom import policies that expose broad standard-library modules
  • Searches for formatter methods that perform object traversal without sandbox authorization checks
  • Policy enforcement that blocks live host objects and unrestricted module imports from sandbox namespaces
  • Runtime monitoring for unexpected file access, process activity, or use of builtins by restricted workloads
  • Automated security review tools can help identify unsafe capability exposure and missing access mediation

Sources

SourceLink
github.comgithub.com/zopefoundation/RestrictedPython/commit/3b47440070b91f8807c2b2998aca99e94783639a
github.comgithub.com/zopefoundation/RestrictedPython/releases/tag/8.4
github.comgithub.com/zopefoundation/RestrictedPython/security/advisories/GHSA-hp3v-5vw7-fx9w

Frequently asked

questions

It can be exploitable through a remote application interface if that interface accepts attacker-controlled Python input and exposes the affected formatter objects. Without such an input path, exploitation is generally limited to users or processes able to submit restricted code.

An attacker needs the ability to execute or influence code inside a RestrictedPython environment, and the environment must expose the standard library string module or a Formatter-related object through imports or globals.

Keep Formatter objects and broad standard-library modules out of restricted namespaces, and ensure every object traversal operation is mediated by sandbox-aware access controls.

Use capability allowlists, expose data-only interfaces, review custom import and global policies, and add isolation and least-privilege controls around sandboxed workloads.

Find out what's already
exploitable in your codebase.