You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I attempt to register ts-node into an instance of NodeVM with options.require.context = "sandbox", I observe the following error. I believe this is likely because ts-node is trying to modify some global state that the sandbox has made read only?
TypeError: 'set' on proxy: trap returned falsish for property 'Symbol(ts-node.register.instance)'
at Object.register (/Users/bburns/projects/petshop/node_modules/ts-node/src/index.ts:586:29)
at /Users/bburns/projects/petshop/node_modules/ts-node/register/index.js:1:78
at BaseHandler.apply (/Users/bburns/projects/truffle/node_modules/vm2/lib/bridge.js:479:11)
at NonStrictNodeVM.run (/Users/bburns/projects/truffle/node_modules/vm2/lib/nodevm.js:425:23)
at NonStrictNodeVM.run (/Users/bburns/projects/truffle/packages/require/lib/index.ts:183:18)
at DefaultResolver.loadJS (/Users/bburns/projects/truffle/node_modules/vm2/lib/resolver.js:203:7)
at loadJS (/Users/bburns/projects/truffle/node_modules/vm2/lib/nodevm.js:248:46)
at BaseHandler.apply (/Users/bburns/projects/truffle/node_modules/vm2/lib/bridge.js:479:11)
at Module._extensions.<computed> (/Users/bburns/projects/truffle/node_modules/vm2/lib/setup-node-sandbox.js:144:48)
at Proxy.requireImpl (/Users/bburns/projects/truffle/node_modules/vm2/lib/setup-node-sandbox.js:117:3)
Note that I'm using the NonStrictNodeVM workaround from #442.
The text was updated successfully, but these errors were encountered:
benjamincburns
changed the title
Cannot register ts-node in sandbox mode
Cannot register ts-node into sandboxed NodeVM instance due to TypeError: 'set' on proxy: trap returned falsishJun 29, 2022
As a workaround I did something like the following (actual code differs, as I'm also working around some path issues).
Important security note: I'm not using sandbox mode for security purposes. I'm just using it to make sure that transitive dependencies of the script that I'm executing in the VM are loaded with the same global context as the script that I'm executing, rather than the host's global context.
consttsNodePath=resolveInUserScriptPath();// function not included for brevityconstcompiler=require(tsNodePath).create().compile;// see #442 comments for implementation of NonStrictNodeVMconstvm=newNonStrictNodeVM({allowAsync: true,console: "inherit",require: {builtin: ["*"],context: "sandbox",external: true},sandbox: {/* globals go here */},
compiler
})
When I attempt to register
ts-node
into an instance ofNodeVM
withoptions.require.context = "sandbox"
, I observe the following error. I believe this is likely becausets-node
is trying to modify some global state that the sandbox has made read only?Note that I'm using the
NonStrictNodeVM
workaround from #442.The text was updated successfully, but these errors were encountered: