Why does Proxy work in n8n Code node but not in standalone @n8n/vm2?

I was going through this commit in @n8n/vm2 which restricts the use of Proxy inside the sandbox:

As expected, when I run the following code in a standalone script using @n8n/vm2, it throws an error:

const { NodeVM } = require('@n8n/vm2');

const vm = new NodeVM({
  sandbox: { },
  require: false,
});

const script = `
  const obj = new Proxy({}, {
    get(target, prop) {
      return 'hello';
    }
  });
  module.exports = obj.test;
`;

console.log(vm.run(script));

Error

TypeError [Error]: Proxy is not a constructor

However, when I use the same logic in an n8n Code node, the workflow executes successfully:

const obj = new Proxy({}, {
  get(target, prop) {
    return 'hello';
  }
});
return $input.all();

So I’m a bit puzzled—if Proxy is supposed to be blocked as per that commit, how is it still allowed within the Code node?

Is there some custom configuration or pre-processing n8n does internally to expose or allow Proxy inside the Code node context?

Information on your n8n setup

  • n8n version: 1.88.0
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Mac OS 14.5
  • n8n/vm2 version: 3.9.25

Our n8n setup was running with task runners enabled, and in that configuration, the Code node was not executed using vm2. That explains why the Proxy object worked fine inside the Code node, even though it’s blocked when using @n8n/vm2 directly in a standalone script.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.