sandboxedjs 0.1.72 → 0.1.74

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,8 +1,8 @@
1
- import { S as Shell, a as ShellIO, b as Session, N as Node, c as Command, K as Kernel, E as ExecContext, O as OutputStream, C as Container, d as createContainer } from './container-BwXE2J26.cjs';
2
- export { B as BufferSink, e as CPythonOptions, f as CallbackSink, g as CommandRegistry, h as ContainerFs, i as ContainerOptions, j as ContextInit, k as Env, l as ExecOptions, m as ExecResult, F as FileData, n as FileInput, o as FileOutput, G as GroupEntry, H as HttpResponse, I as InputStream, J as Job, p as KernelOptions, L as ListeningPort, M as MANIFEST_FORMAT, q as MANIFEST_SCHEMA_VERSION, r as MountEntry, s as NetInterface, t as NetworkOptions, u as NetworkStack, v as NullInput, w as NullOutput, P as PYTHON_VERSION, x as PasswdEntry, y as Pipe, z as Process, A as ProcessKind, D as ProcessOptions, Q as ProcessState, R as ProcessTable, T as PythonCapabilities, U as PythonOptions, V as PythonProfile, W as PythonRuntimeManifest, X as ResolvedExecutable, Y as RunOptions, Z as RunResult, _ as SessionInit, $ as SessionResult, a0 as SessionRunOptions, a1 as ShellExit, a2 as ShellInit, a3 as ShellOptions, a4 as SpawnHandle, a5 as Stdio, a6 as TeeOutput, a7 as UserDatabase, a8 as Variables, a9 as braceExpand, aa as captureStdio, ab as configureCPython, ac as configurePython, ad as createContext, ae as defineCommand, af as expandWord, ag as expandWords, ah as isCPythonAvailable, ai as isPythonAvailable, aj as resetPidCounter, ak as shellQuote, al as validateManifest } from './container-BwXE2J26.cjs';
3
- import { V as Vfs, C as Cred, R as RuntimeVolume, a as VirtualTcpNetwork, b as RuntimeHttpResponse, S as SpawnChild, c as SyncSpawn, d as VolumeStat, e as VolumeStats, f as RuntimePod, g as RuntimePackageInstaller, h as ChildSpawnConfig, i as ChildHandle, j as RuntimeProcess, k as RuntimeSocketPeer, l as RuntimeConnection } from './contracts-CVgctitO.cjs';
4
- export { D as DirEntry, m as ROOT_CRED, n as RuntimeProcessManager, o as RuntimeProcessResult, p as Stats, q as VirtualNode, r as VirtualProvider, W as WriteOptions, s as applyChmod, t as createChildProcessModule, u as formatMode, v as makeCred, w as octalMode, x as parseUmask } from './contracts-CVgctitO.cjs';
5
- import { M as MemoryVolume, a as MemoryVolumeSnapshotEntry } from './memory-volume-DlMSAh-K.cjs';
1
+ import { S as Shell, a as ShellIO, b as Session, N as Node, c as Command, K as Kernel, E as ExecContext, O as OutputStream, C as Container, d as createContainer } from './container-DAWPIkGG.cjs';
2
+ export { B as BufferSink, e as CPythonOptions, f as CallbackSink, g as CommandRegistry, h as ContainerFs, i as ContainerOptions, j as ContextInit, k as Env, l as ExecOptions, m as ExecResult, F as FileData, n as FileInput, o as FileOutput, G as GroupEntry, H as HttpResponse, I as InputStream, J as Job, p as KernelOptions, L as ListeningPort, M as MANIFEST_FORMAT, q as MANIFEST_SCHEMA_VERSION, r as MountEntry, s as NetInterface, t as NetworkOptions, u as NetworkStack, v as NullInput, w as NullOutput, P as PYTHON_VERSION, x as PasswdEntry, y as Pipe, z as Process, A as ProcessKind, D as ProcessOptions, Q as ProcessState, R as ProcessTable, T as PythonCapabilities, U as PythonOptions, V as PythonProfile, W as PythonRuntimeManifest, X as ResolvedExecutable, Y as RunOptions, Z as RunResult, _ as SessionInit, $ as SessionResult, a0 as SessionRunOptions, a1 as ShellExit, a2 as ShellInit, a3 as ShellOptions, a4 as SpawnHandle, a5 as Stdio, a6 as TeeOutput, a7 as UserDatabase, a8 as Variables, a9 as braceExpand, aa as captureStdio, ab as configureCPython, ac as configurePython, ad as createContext, ae as defineCommand, af as expandWord, ag as expandWords, ah as isCPythonAvailable, ai as isPythonAvailable, aj as resetPidCounter, ak as shellQuote, al as validateManifest } from './container-DAWPIkGG.cjs';
3
+ import { V as Vfs, C as Cred, R as RuntimeVolume, a as VirtualTcpNetwork, b as RuntimeHttpResponse, O as OutboundPolicy, S as SpawnChild, c as SyncSpawn, d as VolumeStat, e as VolumeStats, f as RuntimePod, g as RuntimePackageInstaller, h as ChildSpawnConfig, i as ChildHandle, j as RuntimeProcess, k as RuntimeSocketPeer, l as RuntimeConnection } from './contracts-C2_dTgk3.cjs';
4
+ export { D as DirEntry, m as ROOT_CRED, n as RuntimeProcessManager, o as RuntimeProcessResult, p as Stats, q as VirtualNode, r as VirtualProvider, W as WriteOptions, s as applyChmod, t as createChildProcessModule, u as formatMode, v as makeCred, w as octalMode, x as parseUmask } from './contracts-C2_dTgk3.cjs';
5
+ import { M as MemoryVolume, a as MemoryVolumeSnapshotEntry } from './memory-volume-DqEWFo7t.cjs';
6
6
  import EventEmitter from 'events/events.js';
7
7
  import streamModule from 'stream-browserify';
8
8
 
@@ -735,6 +735,24 @@ interface VirtualConnection {
735
735
  /** The far end went away. */
736
736
  close(): void;
737
737
  }
738
+ /** A loopback request, as it crosses from a program to whoever holds the port. */
739
+ interface LoopbackRequest {
740
+ method: string;
741
+ path: string;
742
+ headers: Record<string, string>;
743
+ body: Uint8Array | null;
744
+ }
745
+ interface LoopbackResponse {
746
+ statusCode?: number;
747
+ statusMessage?: string;
748
+ headers?: Record<string, string>;
749
+ body?: string | ArrayBuffer | Uint8Array | null;
750
+ }
751
+ /**
752
+ * Reaches a server in this container that is not on this thread's router.
753
+ * Resolves `null` when nothing in the container listens on the port.
754
+ */
755
+ type LoopbackTransport = (port: number, request: LoopbackRequest) => Promise<LoopbackResponse | null>;
738
756
 
739
757
  interface CoreModulesOptions {
740
758
  volume: RuntimeVolume;
@@ -748,6 +766,13 @@ interface CoreModulesOptions {
748
766
  router: VirtualHttpRouter;
749
767
  owner: string;
750
768
  fetch?: typeof globalThis.fetch;
769
+ /** Servers in other processes, for a router that holds only this thread's. */
770
+ loopback?: LoopbackTransport;
771
+ /**
772
+ * The container's outbound policy, applied to `fetch`, `http`, `https` and
773
+ * `WebSocket`. Omitted, requests leave the way the host's own would.
774
+ */
775
+ policy?: OutboundPolicy;
751
776
  };
752
777
  /** Backs `child_process`; without it the module reports as unavailable. */
753
778
  spawnChild?: SpawnChild;
@@ -813,6 +838,14 @@ declare function createCoreModules(options: CoreModulesOptions): {
813
838
  * exiting in the gap between `http.get` and its response callback.
814
839
  */
815
840
  pendingRequests(): number;
841
+ /** An error that escaped the program's callbacks: listeners, or print and exit 1. */
842
+ reportUncaught(error: unknown): void;
843
+ /** A rejection nobody handled, under the same rule. */
844
+ reportUnhandledRejection(reason: unknown): void;
845
+ /** The status a program ends with: `process.exit`'s code, else `process.exitCode`. */
846
+ exitStatus(): number;
847
+ /** Run `process.on("exit")` listeners once, for a program that ended by itself. */
848
+ emitExit(status: number): void;
816
849
  };
817
850
 
818
851
  interface EsmTransformResult {
@@ -996,6 +1029,12 @@ interface LocalRuntimeOptions {
996
1029
  files?: Record<string, string | Uint8Array>;
997
1030
  registry?: string;
998
1031
  fetch?: typeof globalThis.fetch;
1032
+ /**
1033
+ * The outbound policy for guest `fetch`, `http`, `https` and `WebSocket`.
1034
+ * Omitted, guest requests leave the way the host's would; `createContainer`
1035
+ * always supplies one, closed unless the caller opens it.
1036
+ */
1037
+ network?: OutboundPolicy;
999
1038
  /** Invoked when a program inside the runtime starts listening on a port. */
1000
1039
  onServerReady?: (port: number, url: string) => void;
1001
1040
  /** Extra package substitutions, merged over {@link WASM_ALIASES}. */
@@ -1067,8 +1106,12 @@ declare class LocalRuntimePod implements RuntimePod {
1067
1106
  private rolldownBinding;
1068
1107
  /** Backs outbound `http`/`https` client requests from inside the sandbox. */
1069
1108
  private readonly fetch;
1109
+ /** What guest programs may reach outside the container. */
1110
+ protected networkPolicy: OutboundPolicy | undefined;
1070
1111
  protected constructor(options: LocalRuntimeOptions);
1071
1112
  static boot(options?: LocalRuntimeOptions): Promise<LocalRuntimePod>;
1113
+ /** Apply a container's outbound policy to programs started from now on. */
1114
+ setNetworkPolicy(policy: OutboundPolicy): void;
1072
1115
  spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
1073
1116
  /**
1074
1117
  * Rolldown's JavaScript API synchronously requires its compiled binding.
@@ -1164,6 +1207,15 @@ declare class WorkerRuntimePod extends LocalRuntimePod {
1164
1207
  * the two directions together across the Worker boundary.
1165
1208
  */
1166
1209
  private upgrade;
1210
+ /**
1211
+ * Answer a program that is calling a server in this container.
1212
+ *
1213
+ * A guest's router holds only the servers on its own thread, so a request to
1214
+ * a port some other process opened comes here, where every server in the
1215
+ * container is registered. `null` means nothing listens, which the guest
1216
+ * reports as a refused connection.
1217
+ */
1218
+ private answerLoopback;
1167
1219
  private settleProxied;
1168
1220
  private closeProxies;
1169
1221
  teardown(): void;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { S as Shell, a as ShellIO, b as Session, N as Node, c as Command, K as Kernel, E as ExecContext, O as OutputStream, C as Container, d as createContainer } from './container-WPf_A76-.js';
2
- export { B as BufferSink, e as CPythonOptions, f as CallbackSink, g as CommandRegistry, h as ContainerFs, i as ContainerOptions, j as ContextInit, k as Env, l as ExecOptions, m as ExecResult, F as FileData, n as FileInput, o as FileOutput, G as GroupEntry, H as HttpResponse, I as InputStream, J as Job, p as KernelOptions, L as ListeningPort, M as MANIFEST_FORMAT, q as MANIFEST_SCHEMA_VERSION, r as MountEntry, s as NetInterface, t as NetworkOptions, u as NetworkStack, v as NullInput, w as NullOutput, P as PYTHON_VERSION, x as PasswdEntry, y as Pipe, z as Process, A as ProcessKind, D as ProcessOptions, Q as ProcessState, R as ProcessTable, T as PythonCapabilities, U as PythonOptions, V as PythonProfile, W as PythonRuntimeManifest, X as ResolvedExecutable, Y as RunOptions, Z as RunResult, _ as SessionInit, $ as SessionResult, a0 as SessionRunOptions, a1 as ShellExit, a2 as ShellInit, a3 as ShellOptions, a4 as SpawnHandle, a5 as Stdio, a6 as TeeOutput, a7 as UserDatabase, a8 as Variables, a9 as braceExpand, aa as captureStdio, ab as configureCPython, ac as configurePython, ad as createContext, ae as defineCommand, af as expandWord, ag as expandWords, ah as isCPythonAvailable, ai as isPythonAvailable, aj as resetPidCounter, ak as shellQuote, al as validateManifest } from './container-WPf_A76-.js';
3
- import { V as Vfs, C as Cred, R as RuntimeVolume, a as VirtualTcpNetwork, b as RuntimeHttpResponse, S as SpawnChild, c as SyncSpawn, d as VolumeStat, e as VolumeStats, f as RuntimePod, g as RuntimePackageInstaller, h as ChildSpawnConfig, i as ChildHandle, j as RuntimeProcess, k as RuntimeSocketPeer, l as RuntimeConnection } from './contracts-CVgctitO.js';
4
- export { D as DirEntry, m as ROOT_CRED, n as RuntimeProcessManager, o as RuntimeProcessResult, p as Stats, q as VirtualNode, r as VirtualProvider, W as WriteOptions, s as applyChmod, t as createChildProcessModule, u as formatMode, v as makeCred, w as octalMode, x as parseUmask } from './contracts-CVgctitO.js';
5
- import { M as MemoryVolume, a as MemoryVolumeSnapshotEntry } from './memory-volume-CWuWScIs.js';
1
+ import { S as Shell, a as ShellIO, b as Session, N as Node, c as Command, K as Kernel, E as ExecContext, O as OutputStream, C as Container, d as createContainer } from './container-CsLNpeyi.js';
2
+ export { B as BufferSink, e as CPythonOptions, f as CallbackSink, g as CommandRegistry, h as ContainerFs, i as ContainerOptions, j as ContextInit, k as Env, l as ExecOptions, m as ExecResult, F as FileData, n as FileInput, o as FileOutput, G as GroupEntry, H as HttpResponse, I as InputStream, J as Job, p as KernelOptions, L as ListeningPort, M as MANIFEST_FORMAT, q as MANIFEST_SCHEMA_VERSION, r as MountEntry, s as NetInterface, t as NetworkOptions, u as NetworkStack, v as NullInput, w as NullOutput, P as PYTHON_VERSION, x as PasswdEntry, y as Pipe, z as Process, A as ProcessKind, D as ProcessOptions, Q as ProcessState, R as ProcessTable, T as PythonCapabilities, U as PythonOptions, V as PythonProfile, W as PythonRuntimeManifest, X as ResolvedExecutable, Y as RunOptions, Z as RunResult, _ as SessionInit, $ as SessionResult, a0 as SessionRunOptions, a1 as ShellExit, a2 as ShellInit, a3 as ShellOptions, a4 as SpawnHandle, a5 as Stdio, a6 as TeeOutput, a7 as UserDatabase, a8 as Variables, a9 as braceExpand, aa as captureStdio, ab as configureCPython, ac as configurePython, ad as createContext, ae as defineCommand, af as expandWord, ag as expandWords, ah as isCPythonAvailable, ai as isPythonAvailable, aj as resetPidCounter, ak as shellQuote, al as validateManifest } from './container-CsLNpeyi.js';
3
+ import { V as Vfs, C as Cred, R as RuntimeVolume, a as VirtualTcpNetwork, b as RuntimeHttpResponse, O as OutboundPolicy, S as SpawnChild, c as SyncSpawn, d as VolumeStat, e as VolumeStats, f as RuntimePod, g as RuntimePackageInstaller, h as ChildSpawnConfig, i as ChildHandle, j as RuntimeProcess, k as RuntimeSocketPeer, l as RuntimeConnection } from './contracts-C2_dTgk3.js';
4
+ export { D as DirEntry, m as ROOT_CRED, n as RuntimeProcessManager, o as RuntimeProcessResult, p as Stats, q as VirtualNode, r as VirtualProvider, W as WriteOptions, s as applyChmod, t as createChildProcessModule, u as formatMode, v as makeCred, w as octalMode, x as parseUmask } from './contracts-C2_dTgk3.js';
5
+ import { M as MemoryVolume, a as MemoryVolumeSnapshotEntry } from './memory-volume-CG56p660.js';
6
6
  import EventEmitter from 'events/events.js';
7
7
  import streamModule from 'stream-browserify';
8
8
 
@@ -735,6 +735,24 @@ interface VirtualConnection {
735
735
  /** The far end went away. */
736
736
  close(): void;
737
737
  }
738
+ /** A loopback request, as it crosses from a program to whoever holds the port. */
739
+ interface LoopbackRequest {
740
+ method: string;
741
+ path: string;
742
+ headers: Record<string, string>;
743
+ body: Uint8Array | null;
744
+ }
745
+ interface LoopbackResponse {
746
+ statusCode?: number;
747
+ statusMessage?: string;
748
+ headers?: Record<string, string>;
749
+ body?: string | ArrayBuffer | Uint8Array | null;
750
+ }
751
+ /**
752
+ * Reaches a server in this container that is not on this thread's router.
753
+ * Resolves `null` when nothing in the container listens on the port.
754
+ */
755
+ type LoopbackTransport = (port: number, request: LoopbackRequest) => Promise<LoopbackResponse | null>;
738
756
 
739
757
  interface CoreModulesOptions {
740
758
  volume: RuntimeVolume;
@@ -748,6 +766,13 @@ interface CoreModulesOptions {
748
766
  router: VirtualHttpRouter;
749
767
  owner: string;
750
768
  fetch?: typeof globalThis.fetch;
769
+ /** Servers in other processes, for a router that holds only this thread's. */
770
+ loopback?: LoopbackTransport;
771
+ /**
772
+ * The container's outbound policy, applied to `fetch`, `http`, `https` and
773
+ * `WebSocket`. Omitted, requests leave the way the host's own would.
774
+ */
775
+ policy?: OutboundPolicy;
751
776
  };
752
777
  /** Backs `child_process`; without it the module reports as unavailable. */
753
778
  spawnChild?: SpawnChild;
@@ -813,6 +838,14 @@ declare function createCoreModules(options: CoreModulesOptions): {
813
838
  * exiting in the gap between `http.get` and its response callback.
814
839
  */
815
840
  pendingRequests(): number;
841
+ /** An error that escaped the program's callbacks: listeners, or print and exit 1. */
842
+ reportUncaught(error: unknown): void;
843
+ /** A rejection nobody handled, under the same rule. */
844
+ reportUnhandledRejection(reason: unknown): void;
845
+ /** The status a program ends with: `process.exit`'s code, else `process.exitCode`. */
846
+ exitStatus(): number;
847
+ /** Run `process.on("exit")` listeners once, for a program that ended by itself. */
848
+ emitExit(status: number): void;
816
849
  };
817
850
 
818
851
  interface EsmTransformResult {
@@ -996,6 +1029,12 @@ interface LocalRuntimeOptions {
996
1029
  files?: Record<string, string | Uint8Array>;
997
1030
  registry?: string;
998
1031
  fetch?: typeof globalThis.fetch;
1032
+ /**
1033
+ * The outbound policy for guest `fetch`, `http`, `https` and `WebSocket`.
1034
+ * Omitted, guest requests leave the way the host's would; `createContainer`
1035
+ * always supplies one, closed unless the caller opens it.
1036
+ */
1037
+ network?: OutboundPolicy;
999
1038
  /** Invoked when a program inside the runtime starts listening on a port. */
1000
1039
  onServerReady?: (port: number, url: string) => void;
1001
1040
  /** Extra package substitutions, merged over {@link WASM_ALIASES}. */
@@ -1067,8 +1106,12 @@ declare class LocalRuntimePod implements RuntimePod {
1067
1106
  private rolldownBinding;
1068
1107
  /** Backs outbound `http`/`https` client requests from inside the sandbox. */
1069
1108
  private readonly fetch;
1109
+ /** What guest programs may reach outside the container. */
1110
+ protected networkPolicy: OutboundPolicy | undefined;
1070
1111
  protected constructor(options: LocalRuntimeOptions);
1071
1112
  static boot(options?: LocalRuntimeOptions): Promise<LocalRuntimePod>;
1113
+ /** Apply a container's outbound policy to programs started from now on. */
1114
+ setNetworkPolicy(policy: OutboundPolicy): void;
1072
1115
  spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
1073
1116
  /**
1074
1117
  * Rolldown's JavaScript API synchronously requires its compiled binding.
@@ -1164,6 +1207,15 @@ declare class WorkerRuntimePod extends LocalRuntimePod {
1164
1207
  * the two directions together across the Worker boundary.
1165
1208
  */
1166
1209
  private upgrade;
1210
+ /**
1211
+ * Answer a program that is calling a server in this container.
1212
+ *
1213
+ * A guest's router holds only the servers on its own thread, so a request to
1214
+ * a port some other process opened comes here, where every server in the
1215
+ * container is registered. `null` means nothing listens, which the guest
1216
+ * reports as a refused connection.
1217
+ */
1218
+ private answerLoopback;
1167
1219
  private settleProxied;
1168
1220
  private closeProxies;
1169
1221
  teardown(): void;