sandboxedjs 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,120 @@
1
- import { MemoryVolume, Nodepod } from '@scelar/nodepod';
1
+ import EventEmitter from 'events';
2
+ import streamModule from 'stream-browserify';
3
+
4
+ /** The handle a pod's process manager returns. */
5
+ interface ChildHandle {
6
+ pid: number;
7
+ state: "starting" | "running" | "exited";
8
+ exitCode: number | undefined;
9
+ on(event: "stdout" | "stderr" | "exit", listener: (...args: any[]) => void): unknown;
10
+ exec(): void;
11
+ sendStdin(data: string): void;
12
+ kill(signal?: string): void;
13
+ }
14
+ interface ChildSpawnConfig {
15
+ command: string;
16
+ args?: string[];
17
+ cwd?: string;
18
+ env?: Record<string, string>;
19
+ parentPid?: number;
20
+ }
21
+ type SpawnChild = (config: ChildSpawnConfig) => ChildHandle;
22
+ declare function createChildProcessModule(spawnChild: SpawnChild, defaultCwd: () => string): Record<string, unknown>;
23
+
24
+ /**
25
+ * Clean-room contracts between SandboxedJS and its JavaScript runtime.
26
+ *
27
+ * These deliberately describe only behavior SandboxedJS consumes. Runtime
28
+ * implementations may use Web Workers in browsers or worker_threads on Node.
29
+ */
30
+
31
+ interface VolumeStats {
32
+ totalBytes: number;
33
+ fileCount: number;
34
+ /** New runtime spelling. */
35
+ directoryCount?: number;
36
+ /** Compatibility spelling used by existing volume implementations. */
37
+ dirCount?: number;
38
+ }
39
+ interface VolumeStat {
40
+ mode: number;
41
+ size: number;
42
+ uid: number;
43
+ gid: number;
44
+ ino: number;
45
+ nlink: number;
46
+ atimeMs: number;
47
+ mtimeMs: number;
48
+ ctimeMs: number;
49
+ birthtimeMs: number;
50
+ isFile(): boolean;
51
+ isDirectory(): boolean;
52
+ isSymbolicLink(): boolean;
53
+ }
54
+ interface RuntimeVolume {
55
+ readFileSync(path: string): Uint8Array;
56
+ writeFileSync(path: string, data: string | Uint8Array): void;
57
+ appendFileSync(path: string, data: string | Uint8Array): void;
58
+ readdirSync(path: string): string[];
59
+ lstatSync(path: string): VolumeStat;
60
+ readlinkSync(path: string): string;
61
+ mkdirSync(path: string, options?: {
62
+ mode?: number;
63
+ }): void;
64
+ rmdirSync(path: string): void;
65
+ unlinkSync(path: string): void;
66
+ renameSync(from: string, to: string): void;
67
+ symlinkSync(target: string, path: string): void;
68
+ linkSync(existing: string, path: string): void;
69
+ truncateSync(path: string, length?: number): void;
70
+ chmodSync(path: string, mode: number): void;
71
+ lchmodSync(path: string, mode: number): void;
72
+ chownSync(path: string, uid: number, gid: number): void;
73
+ lchownSync(path: string, uid: number, gid: number): void;
74
+ utimesSync(path: string, atime: Date, mtime: Date): void;
75
+ getStats(): VolumeStats;
76
+ }
77
+ interface RuntimeProcessResult {
78
+ exitCode: number;
79
+ stdout: string;
80
+ stderr: string;
81
+ }
82
+ interface RuntimeProcess {
83
+ readonly completion: Promise<RuntimeProcessResult>;
84
+ on(event: "output" | "error" | "exit", listener: (...args: any[]) => void): this;
85
+ write(data: string): void;
86
+ kill(signal?: string): void;
87
+ }
88
+ interface RuntimeHttpResponse {
89
+ statusCode?: number;
90
+ statusMessage?: string;
91
+ headers?: Record<string, string>;
92
+ body?: string | Uint8Array | ArrayBuffer;
93
+ }
94
+ interface RuntimePackageInstaller {
95
+ install(name: string, version?: string, options?: Record<string, unknown>): Promise<unknown>;
96
+ installFromManifest(path: string, options?: Record<string, unknown>): Promise<unknown>;
97
+ /** Create a view that installs into another project root. */
98
+ forCwd?(cwd: string): RuntimePackageInstaller;
99
+ }
100
+ /** The process-manager protocol a container's kernel bridge substitutes for. */
101
+ interface RuntimeProcessManager {
102
+ spawn(config: ChildSpawnConfig): ChildHandle;
103
+ }
104
+ interface RuntimePod {
105
+ readonly volume: RuntimeVolume;
106
+ readonly packages: RuntimePackageInstaller;
107
+ readonly instanceId: string;
108
+ readonly processManager: RuntimeProcessManager;
109
+ readonly proxy: {
110
+ activePorts(instanceId?: string): number[];
111
+ };
112
+ spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
113
+ request(port: number, init?: Record<string, unknown>): Promise<RuntimeHttpResponse>;
114
+ snapshot(options?: Record<string, unknown>): unknown;
115
+ restore(snapshot: unknown, options?: Record<string, unknown>): Promise<void>;
116
+ teardown(): void;
117
+ }
2
118
 
3
119
  type FileKind = "file" | "directory" | "symlink" | "chardev" | "blockdev" | "fifo" | "socket";
4
120
  /** Render as `drwxr-xr-x`, honouring setuid/setgid/sticky. */
@@ -138,11 +254,11 @@ interface ResolveOptions {
138
254
  followFinal?: boolean;
139
255
  }
140
256
  declare class Vfs {
141
- readonly volume: MemoryVolume;
257
+ readonly volume: RuntimeVolume;
142
258
  private readonly providers;
143
259
  private nextVirtualIno;
144
260
  private readonly virtualInos;
145
- constructor(volume: MemoryVolume);
261
+ constructor(volume: RuntimeVolume);
146
262
  addProvider(provider: VirtualProvider): void;
147
263
  removeProvider(root: string): void;
148
264
  /** The mount points currently served synthetically. */
@@ -665,7 +781,7 @@ declare class NetworkStack {
665
781
  private readonly ifaces;
666
782
  private readonly listeners;
667
783
  readonly options: Required<Pick<NetworkOptions, "allowOutbound">> & NetworkOptions;
668
- constructor(pod: Nodepod, vfs: Vfs, options?: NetworkOptions);
784
+ constructor(pod: RuntimePod, vfs: Vfs, options?: NetworkOptions);
669
785
  interfaces(): NetInterface[];
670
786
  interface(name: string): NetInterface | undefined;
671
787
  setInterfaceUp(name: string, up: boolean): boolean;
@@ -705,7 +821,7 @@ declare class NetworkStack {
705
821
  */
706
822
 
707
823
  interface KernelOptions {
708
- pod: Nodepod;
824
+ pod: RuntimePod;
709
825
  hostname?: string;
710
826
  /** Login user for interactive sessions. Defaults to `root`. */
711
827
  user?: string;
@@ -760,7 +876,7 @@ declare class Kernel {
760
876
  readonly procs: ProcessTable;
761
877
  readonly commands: CommandRegistry;
762
878
  readonly users: UserDatabase;
763
- readonly pod: Nodepod;
879
+ readonly pod: RuntimePod;
764
880
  readonly bootTime: number;
765
881
  readonly memoryBytes: number;
766
882
  readonly cpus: number;
@@ -1502,7 +1618,12 @@ interface ContainerOptions {
1502
1618
  * const box = await createContainer({ pod });
1503
1619
  * ```
1504
1620
  */
1505
- pod?: Nodepod;
1621
+ pod?: RuntimePod;
1622
+ /**
1623
+ * JavaScript runtime implementation. `sandboxedjs` selects the new
1624
+ * clean-room engine while it completes compatibility validation.
1625
+ */
1626
+ runtime?: "sandboxedjs" | "nodepod";
1506
1627
  /** Python runtime settings; a browser host uses this to locate the wasm. */
1507
1628
  python?: PythonOptions;
1508
1629
  /**
@@ -1561,7 +1682,7 @@ interface HttpResponse {
1561
1682
  }
1562
1683
  declare class Container {
1563
1684
  readonly kernel: Kernel;
1564
- readonly pod: Nodepod;
1685
+ readonly pod: RuntimePod;
1565
1686
  readonly fs: ContainerFs;
1566
1687
  readonly net: NetworkStack;
1567
1688
  private readonly defaults;
@@ -2022,6 +2143,466 @@ declare const NODE_VERSION = "v22.12.0";
2022
2143
 
2023
2144
  declare const NPM_VERSION = "10.9.0";
2024
2145
 
2146
+ type NodeKind = "file" | "directory" | "symlink";
2147
+ interface MemoryVolumeSnapshotEntry {
2148
+ path: string;
2149
+ ino: number;
2150
+ kind: NodeKind;
2151
+ mode: number;
2152
+ uid: number;
2153
+ gid: number;
2154
+ nlink: number;
2155
+ data: number[];
2156
+ target: string;
2157
+ atimeMs: number;
2158
+ mtimeMs: number;
2159
+ ctimeMs: number;
2160
+ birthtimeMs: number;
2161
+ }
2162
+ /** Browser-safe, synchronous in-memory filesystem used by the new runtime. */
2163
+ declare class MemoryVolume implements RuntimeVolume {
2164
+ private readonly entries;
2165
+ private nextIno;
2166
+ constructor();
2167
+ readFileSync(path: string): Uint8Array;
2168
+ writeFileSync(path: string, data: string | Uint8Array): void;
2169
+ appendFileSync(path: string, data: string | Uint8Array): void;
2170
+ readdirSync(path: string): string[];
2171
+ lstatSync(path: string): VolumeStat;
2172
+ readlinkSync(path: string): string;
2173
+ mkdirSync(path: string, options?: {
2174
+ mode?: number;
2175
+ }): void;
2176
+ rmdirSync(path: string): void;
2177
+ unlinkSync(path: string): void;
2178
+ renameSync(from: string, to: string): void;
2179
+ symlinkSync(target: string, path: string): void;
2180
+ linkSync(existing: string, path: string): void;
2181
+ truncateSync(path: string, length?: number): void;
2182
+ chmodSync(path: string, mode: number): void;
2183
+ lchmodSync(path: string, mode: number): void;
2184
+ chownSync(path: string, uid: number, gid: number): void;
2185
+ lchownSync(path: string, uid: number, gid: number): void;
2186
+ utimesSync(path: string, atime: Date, mtime: Date): void;
2187
+ getStats(): VolumeStats;
2188
+ snapshot(): MemoryVolumeSnapshotEntry[];
2189
+ restore(snapshot: MemoryVolumeSnapshotEntry[]): void;
2190
+ /** Serializable representation used by RuntimePod snapshots. */
2191
+ export(): Array<{
2192
+ path: string;
2193
+ kind: NodeKind;
2194
+ mode: number;
2195
+ uid: number;
2196
+ gid: number;
2197
+ data?: number[];
2198
+ target?: string;
2199
+ }>;
2200
+ private setMode;
2201
+ private setOwner;
2202
+ private key;
2203
+ private required;
2204
+ private requireParent;
2205
+ private inode;
2206
+ private touchChanged;
2207
+ }
2208
+
2209
+ /**
2210
+ * How a specifier was requested. Node resolves the same package differently
2211
+ * for the two, and a dual package depends on that: `is-promise` exports a
2212
+ * callable function under "require" and a namespace under "import", so
2213
+ * `require("is-promise")` served the ESM build is not merely suboptimal, it is
2214
+ * a `TypeError` at the first call site.
2215
+ */
2216
+ type RequestKind = "import" | "require";
2217
+ interface CommonJsModule {
2218
+ id: string;
2219
+ filename: string;
2220
+ exports: any;
2221
+ loaded: boolean;
2222
+ parent: CommonJsModule | null;
2223
+ children: CommonJsModule[];
2224
+ /**
2225
+ * Set for an ES module whose body contains a top-level `await`: the promise
2226
+ * for its completion. A synchronous `require` of such a module cannot
2227
+ * succeed, and this is what lets the engine say so precisely.
2228
+ */
2229
+ pending?: Promise<void>;
2230
+ }
2231
+ interface CommonJsEngineOptions {
2232
+ volume: RuntimeVolume;
2233
+ cwd?: string;
2234
+ builtins?: Record<string, unknown>;
2235
+ globals?: Record<string, unknown>;
2236
+ /**
2237
+ * Package-name substitutions, applied to bare specifiers before resolution.
2238
+ *
2239
+ * Several cornerstone build tools ship a compiled addon on the platforms
2240
+ * they support and a WebAssembly build for everywhere else — `rollup` and
2241
+ * `@rollup/wasm-node`, `esbuild` and `esbuild-wasm`. This runtime is always
2242
+ * the "everywhere else" case, but the packages select their binding by
2243
+ * reading `process.platform`, which reports a platform whose addon exists
2244
+ * and cannot be loaded. Redirecting the name is how the WebAssembly build
2245
+ * gets chosen instead.
2246
+ *
2247
+ * A substitution that is not installed falls back to the original name, so
2248
+ * an alias is a preference rather than a requirement.
2249
+ */
2250
+ aliases?: Record<string, string>;
2251
+ /**
2252
+ * Modules supplied by the runtime instead of resolved from the filesystem.
2253
+ *
2254
+ * The case this exists for is a toolchain component that cannot execute
2255
+ * inside the sandbox at all. `esbuild` is the example: every build of it
2256
+ * either dlopens a compiled addon or drives a Go/WebAssembly process through
2257
+ * facilities the runtime does not have, so the copy installed in
2258
+ * `node_modules` is unusable no matter which one is chosen. Handing over a
2259
+ * working implementation is what lets the tools built on it run.
2260
+ *
2261
+ * These take precedence over an installed package of the same name but not
2262
+ * over a Node built-in, so an override can never shadow `fs`.
2263
+ */
2264
+ overrides?: Record<string, unknown>;
2265
+ }
2266
+ /**
2267
+ * CommonJS loader for a runtime worker. The worker is the security boundary;
2268
+ * this class intentionally has no dependency on Node's module implementation.
2269
+ */
2270
+ declare class CommonJsEngine {
2271
+ readonly volume: RuntimeVolume;
2272
+ readonly cache: Map<string, CommonJsModule>;
2273
+ readonly builtins: Record<string, unknown>;
2274
+ readonly globals: Record<string, unknown>;
2275
+ readonly aliases: Record<string, string>;
2276
+ readonly overrides: Record<string, unknown>;
2277
+ cwd: string;
2278
+ main: CommonJsModule | null;
2279
+ /** `package.json` per directory; resolution reads them constantly. */
2280
+ private readonly manifests;
2281
+ constructor(volume: RuntimeVolume, options?: Omit<CommonJsEngineOptions, "volume">);
2282
+ /**
2283
+ * Evaluate an entry point.
2284
+ *
2285
+ * Returns the module's exports, or a promise for them when the entry is an
2286
+ * ES module with a top-level `await` — the caller has to await that before
2287
+ * treating the program as finished.
2288
+ */
2289
+ run(entry: string): unknown | Promise<unknown>;
2290
+ require(specifier: string, importer?: string): unknown;
2291
+ resolve(specifier: string, importer: string, kind?: RequestKind): string;
2292
+ private load;
2293
+ private evaluate;
2294
+ /** The `require` a module sees, complete with `resolve`, `cache` and `main`. */
2295
+ private makeRequire;
2296
+ /**
2297
+ * Load `specifier` and present it as an ES module namespace.
2298
+ *
2299
+ * A static `import` is synchronous here, exactly as the CommonJS `require`
2300
+ * it compiles down to. That is the one place this engine knowingly differs
2301
+ * from Node's real ESM semantics, and it is the trade that lets both module
2302
+ * systems share a single cache and resolver.
2303
+ */
2304
+ private importNamespace;
2305
+ /** `import(...)`: the same load, but able to await a top-level `await`. */
2306
+ private dynamicImport;
2307
+ /** `import.meta` for a module. */
2308
+ private importMeta;
2309
+ /**
2310
+ * The substituted specifier for `specifier`, or null when none applies.
2311
+ *
2312
+ * An alias names a package, so a subpath rides along: aliasing `rollup` also
2313
+ * redirects `rollup/dist/native.js` into the substitute.
2314
+ */
2315
+ private aliasFor;
2316
+ /**
2317
+ * Resolve a bare specifier (`pkg`, `@scope/pkg`, `pkg/sub`) by walking
2318
+ * `node_modules` up from the importer, exactly as Node does.
2319
+ */
2320
+ private resolvePackage;
2321
+ /**
2322
+ * Resolve `subpath` ("" for the package root) inside an installed package.
2323
+ *
2324
+ * An `exports` map, when present, is authoritative: Node refuses paths it
2325
+ * does not name, and packages rely on that to keep their internals private.
2326
+ * Only a package without one falls back to `main`/`module` and to treating
2327
+ * the subpath as a plain file path.
2328
+ */
2329
+ private resolveInPackage;
2330
+ /**
2331
+ * Resolve a `#private` specifier through the importing package's `imports`
2332
+ * map, which is scoped to the nearest enclosing package rather than to
2333
+ * `node_modules`.
2334
+ */
2335
+ private resolveImports;
2336
+ /** Resolve a path to a file, trying Node's extension and index fallbacks. */
2337
+ private resolvePath;
2338
+ private resolveIndex;
2339
+ /** The nearest ancestor directory holding a `package.json`. */
2340
+ private packageRoot;
2341
+ private readManifest;
2342
+ private builtin;
2343
+ private exists;
2344
+ private isFile;
2345
+ private isDirectory;
2346
+ private readText;
2347
+ private moduleNotFound;
2348
+ }
2349
+
2350
+ interface VirtualRequestInit {
2351
+ method?: string;
2352
+ path?: string;
2353
+ headers?: Record<string, string>;
2354
+ body?: string | Uint8Array | ArrayBuffer | null;
2355
+ }
2356
+ declare class VirtualIncomingMessage extends streamModule.Readable {
2357
+ readonly method: string;
2358
+ readonly url: string;
2359
+ readonly headers: Record<string, string>;
2360
+ readonly rawHeaders: string[];
2361
+ readonly httpVersion = "1.1";
2362
+ readonly httpVersionMajor = 1;
2363
+ readonly httpVersionMinor = 1;
2364
+ readonly complete = true;
2365
+ readonly socket: Record<string, unknown>;
2366
+ readonly connection: Record<string, unknown>;
2367
+ constructor(init: VirtualRequestInit);
2368
+ _read(): void;
2369
+ setTimeout(_milliseconds: number, callback?: () => void): this;
2370
+ }
2371
+ declare class VirtualServerResponse extends streamModule.Writable {
2372
+ statusCode: number;
2373
+ statusMessage: string;
2374
+ headersSent: boolean;
2375
+ sendDate: boolean;
2376
+ readonly req: VirtualIncomingMessage;
2377
+ readonly socket: Record<string, unknown>;
2378
+ readonly connection: Record<string, unknown>;
2379
+ private readonly headers;
2380
+ private readonly chunks;
2381
+ private resolve;
2382
+ readonly completed: Promise<RuntimeHttpResponse>;
2383
+ constructor(request: VirtualIncomingMessage);
2384
+ _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
2385
+ _final(callback: (error?: Error | null) => void): void;
2386
+ setHeader(name: string, value: string | number | readonly string[]): this;
2387
+ appendHeader(name: string, value: string | readonly string[]): this;
2388
+ getHeader(name: string): string | string[] | undefined;
2389
+ getHeaders(): Record<string, string | string[]>;
2390
+ getHeaderNames(): string[];
2391
+ hasHeader(name: string): boolean;
2392
+ removeHeader(name: string): void;
2393
+ writeHead(statusCode: number, statusMessage?: string | Record<string, unknown>, headers?: Record<string, unknown>): this;
2394
+ flushHeaders(): void;
2395
+ writeContinue(): void;
2396
+ writeProcessing(): void;
2397
+ addTrailers(_headers: Record<string, string>): void;
2398
+ setTimeout(_milliseconds: number, callback?: () => void): this;
2399
+ }
2400
+ declare class VirtualHttpServer extends EventEmitter {
2401
+ private readonly router;
2402
+ readonly owner: string;
2403
+ listening: boolean;
2404
+ private portValue;
2405
+ constructor(router: VirtualHttpRouter, owner: string, listener?: (req: VirtualIncomingMessage, res: VirtualServerResponse) => void);
2406
+ listen(...args: any[]): this;
2407
+ close(callback?: (error?: Error) => void): this;
2408
+ address(): {
2409
+ address: string;
2410
+ family: string;
2411
+ port: number;
2412
+ } | null;
2413
+ ref(): this;
2414
+ unref(): this;
2415
+ setTimeout(_milliseconds: number, callback?: () => void): this;
2416
+ }
2417
+ declare class VirtualHttpRouter {
2418
+ private readonly servers;
2419
+ register(port: number, server: VirtualHttpServer, owner: string): void;
2420
+ unregister(port: number, server: VirtualHttpServer): void;
2421
+ activePorts(owner?: string): number[];
2422
+ closeOwner(owner: string): void;
2423
+ closeAll(): void;
2424
+ request(port: number, init?: VirtualRequestInit): Promise<RuntimeHttpResponse>;
2425
+ }
2426
+
2427
+ interface CoreModulesOptions {
2428
+ volume: RuntimeVolume;
2429
+ cwd?: string;
2430
+ env?: Record<string, string>;
2431
+ argv?: string[];
2432
+ stdout?: (chunk: string) => void;
2433
+ stderr?: (chunk: string) => void;
2434
+ onExit?: (code: number) => void;
2435
+ http?: {
2436
+ router: VirtualHttpRouter;
2437
+ owner: string;
2438
+ };
2439
+ /** Backs `child_process`; without it the module reports as unavailable. */
2440
+ spawnChild?: SpawnChild;
2441
+ }
2442
+ /** Build the core-module table injected into each isolated JS worker. */
2443
+ declare function createCoreModules(options: CoreModulesOptions): {
2444
+ builtins: Record<string, unknown>;
2445
+ globals: Record<string, unknown>;
2446
+ process: Record<string, any>;
2447
+ /**
2448
+ * How many timers this process still has outstanding.
2449
+ *
2450
+ * Node keeps a process alive while its event loop has work, and exits when
2451
+ * it does not. Tracking the timers a program schedules is what lets this
2452
+ * runtime make the same decision — without it a server that binds its port
2453
+ * one turn after its entry module settles looks indistinguishable from a
2454
+ * script that has simply finished.
2455
+ */
2456
+ pendingHandles(): number;
2457
+ };
2458
+
2459
+ interface EsmTransformResult {
2460
+ /** The rewritten source. */
2461
+ code: string;
2462
+ /**
2463
+ * True when the file is an ES module, and so must be evaluated in a wrapper
2464
+ * that does not inject `require`, `module`, `__filename` or `__dirname`.
2465
+ *
2466
+ * False for a CommonJS file that was rewritten only because it contains a
2467
+ * dynamic `import(...)`, which is legal there and still has to be routed
2468
+ * through the engine rather than to the host realm.
2469
+ */
2470
+ esm: boolean;
2471
+ /** True when the module body contains a top-level `await`. */
2472
+ topLevelAwait: boolean;
2473
+ }
2474
+ declare function looksLikeEsm(source: string): boolean;
2475
+ /**
2476
+ * Rewrite `source` from ESM to the engine's CommonJS wrapper shape, or return
2477
+ * `null` when it is not an ES module and should be evaluated as-is.
2478
+ *
2479
+ * `null` is also returned when the source does not parse as a module: that is
2480
+ * not this function's error to raise. Letting it through means the engine
2481
+ * evaluates the original text and the runtime reports the real syntax error at
2482
+ * the real position.
2483
+ */
2484
+ declare function transformEsm(source: string, filename?: string): EsmTransformResult | null;
2485
+
2486
+ interface LocalRuntimeOptions {
2487
+ workdir?: string;
2488
+ env?: Record<string, string>;
2489
+ files?: Record<string, string | Uint8Array>;
2490
+ registry?: string;
2491
+ fetch?: typeof globalThis.fetch;
2492
+ /** Extra package substitutions, merged over {@link WASM_ALIASES}. */
2493
+ aliases?: Record<string, string>;
2494
+ /** Modules supplied by the host rather than resolved from the volume. */
2495
+ modules?: Record<string, unknown>;
2496
+ /**
2497
+ * Supply `esbuild` from the host when it can be loaded. On by default: no
2498
+ * build of esbuild runs inside the sandbox, so without this every toolchain
2499
+ * that depends on it — Vite included — starts and then fails on the first
2500
+ * transform.
2501
+ */
2502
+ hostEsbuild?: boolean;
2503
+ }
2504
+ /**
2505
+ * Default substitutions for packages that would otherwise load a compiled
2506
+ * addon.
2507
+ *
2508
+ * Each of these ships a WebAssembly build under a second package name for
2509
+ * exactly this situation — a host with no prebuilt binary for its platform.
2510
+ * The substitute is only used when it is actually installed, so a project that
2511
+ * has neither is unaffected and one that has both gets the runnable one.
2512
+ */
2513
+ declare const WASM_ALIASES: Record<string, string>;
2514
+ /**
2515
+ * First complete clean-room RuntimePod composition. Execution currently uses
2516
+ * the caller's JS realm; BrowserRuntimePod will place the same engine in a
2517
+ * dedicated Worker before this becomes the default untrusted-code path.
2518
+ */
2519
+ declare class LocalRuntimePod implements RuntimePod {
2520
+ readonly volume: MemoryVolume;
2521
+ readonly packages: RuntimePackageInstaller;
2522
+ readonly instanceId: string;
2523
+ private readonly router;
2524
+ readonly proxy: {
2525
+ activePorts: (_instanceId?: string) => number[];
2526
+ };
2527
+ /**
2528
+ * Mutable on purpose: a container replaces `spawn` so that children resolve
2529
+ * against the kernel's PATH. Left alone, it runs `node` and reports anything
2530
+ * else as not found, which is the correct answer for a bare pod.
2531
+ */
2532
+ readonly processManager: {
2533
+ spawn(config: ChildSpawnConfig): ChildHandle;
2534
+ };
2535
+ private disposed;
2536
+ private readonly workdir;
2537
+ private readonly env;
2538
+ private readonly aliases;
2539
+ private readonly modules;
2540
+ private constructor();
2541
+ static boot(options?: LocalRuntimeOptions): Promise<LocalRuntimePod>;
2542
+ spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
2543
+ /**
2544
+ * Wait until the process has either started serving or genuinely run out of
2545
+ * work.
2546
+ *
2547
+ * Timers are the observable half of the event loop, so a process with none
2548
+ * outstanding and no port open has finished — and, being the common case for
2549
+ * a plain script, is settled without waiting at all.
2550
+ */
2551
+ private settle;
2552
+ request(_port: number, _init?: Record<string, unknown>): Promise<RuntimeHttpResponse>;
2553
+ snapshot(): MemoryVolumeSnapshotEntry[];
2554
+ restore(snapshot: unknown): Promise<void>;
2555
+ teardown(): void;
2556
+ private seed;
2557
+ private assertActive;
2558
+ }
2559
+
2560
+ interface RegistryManifest {
2561
+ name: string;
2562
+ version: string;
2563
+ dist: {
2564
+ tarball: string;
2565
+ integrity?: string;
2566
+ shasum?: string;
2567
+ };
2568
+ dependencies?: Record<string, string>;
2569
+ optionalDependencies?: Record<string, string>;
2570
+ bin?: string | Record<string, string>;
2571
+ }
2572
+ interface CleanInstallerOptions {
2573
+ cwd?: string;
2574
+ registry?: string;
2575
+ fetch?: typeof globalThis.fetch;
2576
+ }
2577
+ interface InstallOptions extends Record<string, unknown> {
2578
+ onProgress?: (message: string) => void;
2579
+ persist?: boolean;
2580
+ persistDev?: boolean;
2581
+ withDevDeps?: boolean;
2582
+ }
2583
+ /** npm-registry installer independent of npm CLI and Node host APIs. */
2584
+ declare class CleanPackageInstaller implements RuntimePackageInstaller {
2585
+ readonly volume: RuntimeVolume;
2586
+ readonly options: CleanInstallerOptions;
2587
+ private readonly registry;
2588
+ private readonly fetcher;
2589
+ private readonly metadata;
2590
+ private readonly tarballs;
2591
+ constructor(volume: RuntimeVolume, options?: CleanInstallerOptions);
2592
+ forCwd(cwd: string): CleanPackageInstaller;
2593
+ install(name: string, version?: string, options?: InstallOptions): Promise<RegistryManifest>;
2594
+ installFromManifest(path: string, options?: InstallOptions): Promise<void>;
2595
+ private installAt;
2596
+ private getMetadata;
2597
+ private getTarball;
2598
+ private createBinLinks;
2599
+ private persist;
2600
+ private removeIfPresent;
2601
+ private readJson;
2602
+ private tryReadJson;
2603
+ }
2604
+ declare function extractNpmTarball(volume: RuntimeVolume, compressed: Uint8Array, destination: string): void;
2605
+
2025
2606
  /**
2026
2607
  * sandboxedjs — a Linux-like container that runs entirely inside Node.js.
2027
2608
  *
@@ -2040,4 +2621,4 @@ declare const NPM_VERSION = "10.9.0";
2040
2621
  * ```
2041
2622
  */
2042
2623
 
2043
- export { ArithError, BufferSink, type CPythonOptions, CallbackSink, type Command, CommandRegistry, Container, ContainerFs, type ContainerOptions, type ContextInit, type Cred, type DirEntry, ERRNO, type Env, type ErrnoCode, type ExecContext, type ExecOptions, type ExecResult, type FileData, FileInput, FileOutput, type GroupEntry, type HttpResponse, IncompleteInputError, type InputStream, type Job, KERNEL_NAME, KERNEL_RELEASE, Kernel, type KernelOptions, type ListeningPort, type MountEntry, NODE_VERSION, NPM_VERSION, type NetInterface, type NetworkOptions, NetworkStack, NullInput, NullOutput, OS_RELEASE, type OutputStream, PYTHON_VERSION, type PasswdEntry, Pipe, Process, type ProcessKind, type ProcessOptions, type ProcessState, ProcessTable, type PythonOptions, ROOT_CRED, type ResolvedExecutable, type RootfsOptions, type RunOptions, type RunResult, SIGNALS, SIGNAL_NAMES, Session, type SessionInit, type SessionResult, type SessionRunOptions, Shell, ShellExit, type ShellIO, type ShellInit, Lexer as ShellLexer, type ShellOptions, ShellSyntaxError, type SpawnHandle, Stats, type Stdio, SysError, TeeOutput, Terminal, type TerminalOptions, UserDatabase, Variables, Vfs, type VirtualNode, type VirtualProvider, type WriteOptions, allCommands, applyChmod, braceExpand, buildRootfs, builtinNames, captureStdio, configureCPython, configurePython, createContainer, createContext, createContainer as default, defineCommand, evalArith, exitCodeForSignal, expandPrompt, expandWord, expandWords, fnmatch, formatMode, getBuiltin, glob, globToRegex, hasMagic, installUserland, isBuiltinName, isCPythonAvailable, isPythonAvailable, isSysError, makeCred, normalizeSignal, octalMode, parse as parseShell, parseUmask, path as posixPath, resetPidCounter, shellQuote, strerror, unameInfo };
2624
+ export { ArithError, BufferSink, type CPythonOptions, CallbackSink, type ChildHandle, type ChildSpawnConfig, type CleanInstallerOptions, CleanPackageInstaller, type Command, CommandRegistry, CommonJsEngine, type CommonJsEngineOptions, type CommonJsModule, Container, ContainerFs, type ContainerOptions, type ContextInit, type CoreModulesOptions, type Cred, type DirEntry, ERRNO, type Env, type ErrnoCode, type EsmTransformResult, type ExecContext, type ExecOptions, type ExecResult, type FileData, FileInput, FileOutput, type GroupEntry, type HttpResponse, IncompleteInputError, type InputStream, type InstallOptions, type Job, KERNEL_NAME, KERNEL_RELEASE, Kernel, type KernelOptions, type ListeningPort, type LocalRuntimeOptions, LocalRuntimePod, MemoryVolume, type MountEntry, NODE_VERSION, NPM_VERSION, type NetInterface, type NetworkOptions, NetworkStack, NullInput, NullOutput, OS_RELEASE, type OutputStream, PYTHON_VERSION, type PasswdEntry, Pipe, Process, type ProcessKind, type ProcessOptions, type ProcessState, ProcessTable, type PythonOptions, ROOT_CRED, type ResolvedExecutable, type RootfsOptions, type RunOptions, type RunResult, type RuntimePackageInstaller, type RuntimePod, type RuntimeProcess, type RuntimeProcessManager, type RuntimeProcessResult, type RuntimeVolume, SIGNALS, SIGNAL_NAMES, Session, type SessionInit, type SessionResult, type SessionRunOptions, Shell, ShellExit, type ShellIO, type ShellInit, Lexer as ShellLexer, type ShellOptions, ShellSyntaxError, type SpawnChild, type SpawnHandle, Stats, type Stdio, SysError, TeeOutput, Terminal, type TerminalOptions, UserDatabase, Variables, Vfs, VirtualHttpRouter, VirtualHttpServer, VirtualIncomingMessage, type VirtualNode, type VirtualProvider, VirtualServerResponse, WASM_ALIASES, type WriteOptions, allCommands, applyChmod, braceExpand, buildRootfs, builtinNames, captureStdio, configureCPython, configurePython, createChildProcessModule, createContainer, createContext, createCoreModules, createContainer as default, defineCommand, evalArith, exitCodeForSignal, expandPrompt, expandWord, expandWords, extractNpmTarball, fnmatch, formatMode, getBuiltin, glob, globToRegex, hasMagic, installUserland, isBuiltinName, isCPythonAvailable, isPythonAvailable, isSysError, looksLikeEsm, makeCred, normalizeSignal, octalMode, parse as parseShell, parseUmask, path as posixPath, resetPidCounter, shellQuote, strerror, transformEsm, unameInfo };