Back to Botpress

README

packages/llmz/examples/18_worker_security/README.md

12.30.93.4 KB
Original Source

πŸ”’ Secure Code Execution

The code generated by LLMz runs in a hardened Node.js isolate. Each iteration is sandboxed in its own isolated VM context with strict execution limits.

πŸ–₯️ Fully Local and Self-Contained

LLMz runs entirely locally. It does not:

  • Rely on external SaaS
  • Use Docker or Linux containers
  • Make any outbound web calls

Instead, it uses V8 Isolates β€” the same secure sandboxing technology used by Chrome, Edge, and other modern browsers to run extensions, untrusted scripts, and web pages in separate memory-safe environments.

This gives LLMz the same low-level isolation primitives trusted at internet scale β€” but applied locally, with full control.

🧱 Enforced Sandbox Restrictions:

  • require, process, Buffer, setImmediate are not defined.
  • Execution time is strictly limited per iteration.
  • Memory usage is capped, triggering isolate disposal on abuse.
  • Global objects like console, globalThis, this.constructor are locked down or sanitized.
  • Each code run is in a new context, so persistent tampering doesn't carry over.

πŸŽ₯ Demo

βœ… Prevented and Blocked Attacks:

CategoryAttackStatus
Filesystemrm -rf /, fs.writeFileSync, fs.readFileSync❌ require is blocked – file system access denied
Process Accessprocess.env, process.cwd()❌ process is not defined
Require AbuseNative module loading, require.cache, hijacking require()❌ require is not defined
Infinite Loopswhile (true), recursion, memory growthβœ… Terminated by timeout or memory cap (execution_error, Isolate disposed)
Global Escapethis.constructor.constructor('return process')()❌ this.constructor is undefined
Async Resource LoopssetImmediate, Promise flood❌ setImmediate not defined, Promises fail to clone
Buffer AbuseBuffer.allocUnsafe(...)❌ Buffer is not defined
Global Leak AttemptsglobalThis, console hijackingβœ… Execution fails or isolate gets killed

⚠️ Disclaimer

You should not run arbitrary user-submitted code (e.g. copy-pasted by users, not generated by LLMz) next to your production backend β€” even inside LLMz.

While LLMz provides a robust sandbox, it is not a complete isolation layer suitable for multi-tenant production security.

On Botpress Cloud, each customer runs:

  • In their own completely isolated AWS Lambda environment
  • With stripped privileges
  • On top of the LLMz sandbox

That’s the level of defense-in-depth required to run unknown code safely at scale.