{"record":{"id":"44509904b49b83af","repo":"FlowiseAI/Flowise","slug":"nodevm-execution-error-e","errorCode":null,"errorMessage":"NodeVM Execution Error: ${e}","messagePattern":"NodeVM Execution Error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/src/utils.ts","lineNumber":1809,"sourceCode":"        const vm = new NodeVM(finalNodeVMOptions)\n\n        try {\n            const response = await vm.run(`module.exports = async function() {${code}}()`, __dirname)\n\n            let finalOutput = response\n\n            // Stream output if streaming function provided\n            if (streamOutput && finalOutput) {\n                let streamOutputString = finalOutput\n                if (typeof response === 'object') {\n                    streamOutputString = JSON.stringify(finalOutput, null, 2)\n                }\n                streamOutput(streamOutputString)\n            }\n\n            return parseOutput(finalOutput)\n        } catch (e) {\n            throw new Error(`NodeVM Execution Error: ${e}`)\n        }\n    }\n}\n\n/**\n * Create a standard sandbox object for code execution\n * @param {string} input - The input string\n * @param {ICommonObject} variables - Variables from getVars\n * @param {ICommonObject} flow - Flow object with chatflowId, sessionId, etc.\n * @param {ICommonObject} additionalSandbox - Additional sandbox variables\n * @returns {ICommonObject} - The sandbox object\n */\nexport const createCodeExecutionSandbox = (\n    input: string,\n    variables: IVariable[],\n    flow: ICommonObject,\n    additionalSandbox: ICommonObject = {}\n): ICommonObject => {","sourceCodeStart":1791,"sourceCodeEnd":1827,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/src/utils.ts#L1791-L1827","documentation":"Outer catch-all wrapping exceptions from the NodeVM (vm2) branch of executeJavascript. It catches vm.run failures (sandboxed code threw, syntax error, disallowed require, timeout), parseOutput failures, or streamOutput errors — rewrapping as 'NodeVM Execution Error: <e>'.","triggerScenarios":"User code references a require('fs') that isn't in builtinDeps; code imports an external module not in the deps allow-list; vm2 timeout exceeded (timeoutMs); code throws a non-serializable value; parseOutput chokes on a Symbol/function return value.","commonSituations":"ALLOW_BUILTIN_DEP not set to 'true' so built-in modules are blocked; TOOL_FUNCTION_EXTERNAL_DEP missing the package the custom tool needs; vm2 timeout too low for the workload; returned value is undefined or a function which JSON.stringify can't handle.","solutions":["Read <e> in the message — vm2 surfaces 'Access denied to require ...' or timeout specifics.","Add the needed module to TOOL_FUNCTION_EXTERNAL_DEP (external) or set ALLOW_BUILTIN_DEP=true (built-ins).","Increase the timeoutMs for the tool node if the workload legitimately needs more time.","Make the custom function return JSON-serializable data (plain objects/arrays/primitives)."],"exampleFix":"// before\n} catch (e) {\n  throw new Error(`NodeVM Execution Error: ${e}`)\n}\n\n// after — classify vm2 denial vs timeout vs user error\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e)\n  if (/Access denied to require/.test(msg)) {\n    throw new Error(`NodeVM: disallowed module. Add it to TOOL_FUNCTION_EXTERNAL_DEP or enable ALLOW_BUILTIN_DEP. Detail: ${msg}`)\n  }\n  if (/timeout/i.test(msg)) {\n    throw new Error(`NodeVM: execution timed out. Increase the node timeoutMs. Detail: ${msg}`)\n  }\n  throw new Error(`NodeVM Execution Error: ${msg}`, { cause: e })\n}","handlingStrategy":"try-catch","validationCode":"function assertDepsAllowed(imports: string[], env: NodeJS.ProcessEnv) {\n  const external = (env.TOOL_FUNCTION_EXTERNAL_DEP || '').split(',').filter(Boolean)\n  const missing = imports.filter((m) => !external.includes(m))\n  if (missing.length) throw new Error(`Disallowed modules: ${missing.join(', ')}`)\n}","typeGuard":"function isVm2AccessDenied(e: unknown): boolean {\n  return e instanceof Error && /Access denied to require/i.test(e.message)\n}","tryCatchPattern":"} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e)\n  if (/Access denied to require/.test(msg)) {\n    throw new Error(`Disallowed module. Update TOOL_FUNCTION_EXTERNAL_DEP or set ALLOW_BUILTIN_DEP=true. Detail: ${msg}`)\n  }\n  throw new Error(`NodeVM Execution Error: ${msg}`, { cause: e })\n}","preventionTips":["Keep TOOL_FUNCTION_EXTERNAL_DEP and ALLOW_BUILTIN_DEP documented for tool authors.","Set a generous but bounded timeoutMs for vm.run.","Have custom tools return plain JSON-serializable values."],"tags":["nodevm","vm2","javascript-execution","error-wrapping","sandbox"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}