/** * The `node:vm` module enables compiling and running code within V8 Virtual * Machine contexts. * * **The `node:vm` module is not a security** * **mechanism. Do not use it to run untrusted code.** * * JavaScript code can be compiled and run immediately or * compiled, saved, and run later. * * A common use case is to run the code in a different V8 Context. This means * invoked code has a different global object than the invoking code. * * One can provide the context by `contextifying` an * object. The invoked code treats any property in the context like a * global variable. Any changes to global variables caused by the invoked * code are reflected in the context object. * * ```js * import vm from 'node:vm'; * * const x = 1; * * const context = { x: 2 }; * vm.createContext(context); // Contextify the object. * * const code = 'x += 40; var y = 17;'; * // `x` and `y` are global variables in the context. * // Initially, x has the value 2 because that is the value of context.x. * vm.runInContext(code, context); * * console.log(context.x); // 42 * console.log(context.y); // 17 * * console.log(x); // 1; y is not defined. * ``` * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/vm.js) */ declare module "vm" { import { ImportAttributes } from "node:module"; interface Context extends NodeJS.Dict {} interface BaseOptions { /** * Specifies the filename used in stack traces produced by this script. * @default '' */ filename?: string | undefined; /** * Specifies the line number offset that is displayed in stack traces produced by this script. * @default 0 */ lineOffset?: number | undefined; /** * Specifies the column number offset that is displayed in stack traces produced by this script. * @default 0 */ columnOffset?: number | undefined; } type DynamicModuleLoader = ( specifier: string, referrer: T, importAttributes: ImportAttributes, phase: "source" | "evaluation", ) => Module | Promise; interface ScriptOptions extends BaseOptions { /** * Provides an optional data with V8's code cache data for the supplied source. */ cachedData?: Buffer | NodeJS.ArrayBufferView | undefined; /** @deprecated in favor of `script.createCachedData()` */ produceCachedData?: boolean | undefined; /** * Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is * part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see * [Support of dynamic `import()` in compilation APIs](https://nodejs.org/docs/latest-v24.x/api/vm.html#support-of-dynamic-import-in-compilation-apis). * @experimental */ importModuleDynamically?: | DynamicModuleLoader