{"record":{"id":"681d66e4fc82df40","repo":"DIYgod/RSSHub","slug":"vm-runinnewcontext-is-not-supported-in-workers","errorCode":null,"errorMessage":"vm.runInNewContext is not supported in Workers","messagePattern":"vm\\.runInNewContext is not supported in Workers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/shims/node-module.ts","lineNumber":68,"sourceCode":"    }\n    runInContext() {\n        throw new Error('vm.Script.runInContext is not supported in Workers');\n    }\n    runInNewContext() {\n        throw new Error('vm.Script.runInNewContext is not supported in Workers');\n    }\n    runInThisContext() {\n        throw new Error('vm.Script.runInThisContext is not supported in Workers');\n    }\n}\n\nconst vmShim = {\n    createContext: (sandbox?: object) => sandbox || {},\n    runInContext: () => {\n        throw new Error('vm.runInContext is not supported in Workers');\n    },\n    runInNewContext: () => {\n        throw new Error('vm.runInNewContext is not supported in Workers');\n    },\n    runInThisContext: () => {\n        throw new Error('vm.runInThisContext is not supported in Workers');\n    },\n    Script: ScriptShim,\n    isContext: () => false,\n    compileFunction: () => {\n        throw new Error('vm.compileFunction is not supported in Workers');\n    },\n};\n\n// Child process shim (inline to avoid import cycle)\nconst child_process = {\n    execSync: (_command: string): Buffer => Buffer.from(''),\n    exec: () => {\n        throw new Error('exec is not supported in Cloudflare Workers');\n    },\n    spawn: () => {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/node-module.ts#L50-L86","documentation":"vmShim.runInNewContext() in lib/shims/node-module.ts throws — Workers cannot spin up a new isolated context for code execution. This is the functional-form counterpart to ScriptShim.runInNewContext and fails for the same runtime reason.","triggerScenarios":"Calling vm.runInNewContext(code, sandbox) under Workers; some bundlers/loaders and sandbox libraries use this form.","commonSituations":"Sandboxing third-party/untrusted code; polyfills that evaluate snippets per-call.","solutions":["Do not call runInNewContext under Workers.","Precompile the snippet at build time or replace with static logic.","Move the eval-dependent route to Node."],"exampleFix":"// before\nvm.runInNewContext(code, sandbox);\n// after\nconst fn = precompiledFns[name]; // build-time map, no runtime eval","handlingStrategy":"validation","validationCode":"const vmUsable = typeof process !== 'undefined' && !!process.versions?.node;\nif (!vmUsable) {\n  // skip vm.runInNewContext; precompile instead\n}","typeGuard":"function isVmShimError(e: unknown): e is Error {\n  return e instanceof Error && /not supported in Workers/.test(e.message);\n}","tryCatchPattern":"try {\n  if (vmUsable) vm.runInNewContext(code, sandbox);\n  else return precompiledFns[name](data);\n} catch (e) {\n  if (isVmShimError(e)) return precompiledFns[name](data);\n  throw e;\n}","preventionTips":["Never sandbox-eval untrusted code under Workers.","Precompile to a function map at build time.","Keep per-call sandbox execution on Node."],"tags":["cloudflare-workers","vm","runtime","shim"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}