Why use Node.js vm module instead of `isolated-vm` for sandboxed LLM code execution?
Question: Why use Node.js vm module instead of isolated-vm for sandboxing?
While the implementation in packages/code-mode/src/code_mode_utcp_client.ts leverages Node.js's native vm module for executing LLM-generated TypeScript code in a sandboxed environment, I'm curious about the decision not to use isolated-vm instead. The isolated-vm library is widely regarded for its stronger isolation guarantees, being designed specifically to prevent untrusted code from escaping its sandbox and interfering with the host process or other sandboxes.
Context:
- The
vmmodule executes code in a V8 context, but shares the same thread and some global objects with the parent Node.js process. isolated-vmcreates true isolates in V8, preventing most forms of escape and providing much tighter separation, which is especially critical for running untrusted or LLM-generated code.
Questions:
- What are the technical or practical reasons for preferring
vmoverisolated-vmin this codebase? - Are there limitations, compatibility issues, or performance concerns that led to this choice?
- Are there plans or discussions to adopt
isolated-vmin the future for enhanced security and isolation?
References:
This question is particularly relevant as LLM-generated code may be untrusted, and robust sandboxing is critical for security. Would appreciate insight from maintainers or those familiar with the design decisions here.
The main issue with the isolated-vm implementation is that it's much more complicated to get the tools called in the code to execute in the main process. This is necessary for a consistent state for tools such as the PlayWrite MCP, which would not work directly in the isolated-vm.
That being said, we are looking to switch to isolated-vm and are welcoming any contributions in that direction!