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.
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.
Did you set builtin: ['fs']
?
Try the below code sample
const {NodeVM} = require('vm2');
const vm = new NodeVM({
console: 'inherit',
sandbox: {},
require: {
external: true,
builtin: ['fs', 'path'],
root: "./",
mock: {
fs: {
readFileSync() { return 'Nice try!'; }
}
}
}
});