vm2 is a Node.js sandbox that can run untrusted code with whitelisted Node's built-in modules.
Questions tagged [node-vm2]
25 questions
1
vote
1 answer
Node.js vm2 exchanging information between VM and main code using functions
I am using the vm2 module, and I have some code with two functions: get_input() for getting some data that I have, and display() for showing some data, but these functions will not be defined in that code. How do I make some sort of external…

ICanKindOfCode
- 1,000
- 1
- 11
- 32
1
vote
1 answer
How to end any code currently being run by Node VM2
I am running some sandboxed code in Node using vm2.
The code being run will be mostly asynchronous. It is untrusted code, and can not be relied upon to conform in any way- hence why I'm using vm2 to run it.
Does vm2 have a way of ending any code…

Jodes
- 14,118
- 26
- 97
- 156
1
vote
0 answers
Running "module.exports = function(foo){...}" in Node vm2
I'm new to Node and the virtual machine vm2. In the documentation for the latter, it gives an example of its usage:
let functionInSandbox = vm.run("module.exports = function(who) { console.log('hello '+ who);…

Jodes
- 14,118
- 26
- 97
- 156
0
votes
0 answers
Is there any way to run JavaScript code in an isolated environment with dependencies, similar to Node.js?
I've tried using the isolated-vm and vm2 libraries to run code in an isolated environment, but I've run into issues where the required packages are not installed in the isolated environment.
isolated-vm not support module and vm2 not installing it…

Lakhan gaikwad
- 1
- 4
0
votes
1 answer
How to use node modules inside VM2 sandbox
I'm trying to run a user-submitted script in a sandbox to process some data, before sending the output to a specified end point through a http request via node-fetch. However, I'm not sure if I am even doing it correctly, even after reading the…

jun
- 192
- 15
0
votes
2 answers
Prevent infinite loop when using NodeVM with code injection rather than threads
Lately am building an API with Node.js that receives untrusted code to run it using vm2.
The issue is I want to run async functions, so I need to use NodeVM which does not support timeout for infinite loop, the solutions that I found all about using…

DanTe
- 115
- 6
0
votes
0 answers
VM2 memory leakage
How we will solve this problem of memory leakage? When I am hitting 100 concurrent multiple requests, each time VM2 creating new process and memory leakage occur. How to solve this problem?

Cyrus
- 1
0
votes
1 answer
How to allow filesystem access
I want to provide filesystem access for use with fs. How can I grant the vm2 process access to a specific directory?
I've tried setting external to true and a root of /. The process is able to access the directory when run outside vm2.
0
votes
1 answer
Reference error when trying to return a string Nodejs VM
I'm using a npm module called safe-eval to evaluate some JavaScript code i send to the backend. The code is usually a function that will be executed inside of the safe-eval with the parameters I'll provide. The problem is that when returning certain…

shamil carela
- 74
- 8
0
votes
1 answer
Nodejs vm2 - how to import scripts
Suppose you have script A: defines a library with:
class MathFunctions { add(a, b) => { return a+b; } }
And you have script B: reuses MathFunctions somehow:
const mf = import MathFunctions;
console.log(mf.add(2, 2));
And you want to execute B in…

Robert Christian
- 18,218
- 20
- 74
- 89