sandboxedjs 0.1.7 → 0.1.8

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
@@ -613,6 +613,58 @@ interface ContextInit {
613
613
  }
614
614
  declare function createContext(init: ContextInit): ExecContext;
615
615
 
616
+ /**
617
+ * Executable format handlers — the container's `binfmt_misc`.
618
+ *
619
+ * The kernel knows how to dispatch two things by itself: a built-in command,
620
+ * and a text file with a `#!` line. Everything else is a binary, and the kernel
621
+ * deliberately knows nothing about what any particular binary is. Instead it
622
+ * sniffs the first bytes of the file and asks this registry who can run it.
623
+ *
624
+ * That indirection is the whole point. A format handler is registered at boot
625
+ * like a driver, so support for a new kind of executable is a handler, never a
626
+ * special case in `dispatch` and never a list of blessed program names. When a
627
+ * user drops a `wasm32-wasi` build of `jq` into `/usr/local/bin` and marks it
628
+ * executable, it runs — not because anything here has heard of `jq`, but
629
+ * because something here has heard of WebAssembly.
630
+ *
631
+ * A handler with no `run` is still worth registering: recognising an ELF binary
632
+ * well enough to say "this is an x86-64 Linux executable and nothing in this
633
+ * container can execute it" is far more use than `Exec format error`.
634
+ */
635
+
636
+ interface ExecFormat {
637
+ /** Short identifier, e.g. `wasi`. Shown by `file` and in diagnostics. */
638
+ readonly name: string;
639
+ /**
640
+ * Handlers are consulted in ascending priority, so a specific format can be
641
+ * tested before a broader one. Defaults to 50.
642
+ */
643
+ readonly priority?: number;
644
+ /** True when `head` is this format. Must not throw. */
645
+ matches(head: Uint8Array, path: string): boolean;
646
+ /** Human-readable description for `file`. */
647
+ describe?(head: Uint8Array, path: string): string;
648
+ /**
649
+ * Execute the file. `ctx.args` holds the arguments, exactly as for a
650
+ * built-in. Omit to register a format that is recognised but not runnable.
651
+ */
652
+ run?(ctx: ExecContext, path: string): Promise<number> | number;
653
+ /**
654
+ * Lines explaining why the format cannot run here, printed in place of
655
+ * `Exec format error`. Only consulted when `run` is absent.
656
+ */
657
+ explain?(head: Uint8Array, path: string): string[];
658
+ }
659
+ declare class ExecFormatRegistry {
660
+ private readonly formats;
661
+ register(format: ExecFormat): void;
662
+ registerAll(formats: ExecFormat[]): void;
663
+ /** The handler claiming `head`, or null when the bytes match nothing. */
664
+ match(head: Uint8Array, path: string): ExecFormat | null;
665
+ list(): ExecFormat[];
666
+ }
667
+
616
668
  /**
617
669
  * The container's network stack.
618
670
  *
@@ -738,7 +790,7 @@ interface RunResult {
738
790
  signal: string | null;
739
791
  timedOut: boolean;
740
792
  }
741
- type ExecutableKind = "builtin" | "script" | "unknown";
793
+ type ExecutableKind = "builtin" | "script" | "binary" | "unknown";
742
794
  interface ResolvedExecutable {
743
795
  kind: ExecutableKind;
744
796
  /** Absolute path of the file that was found. */
@@ -747,6 +799,10 @@ interface ResolvedExecutable {
747
799
  command?: Command;
748
800
  /** Interpreter argv from a `#!` line, when `kind === "script"`. */
749
801
  interpreter?: string[];
802
+ /** The registered handler for the file's magic, when `kind === "binary"`. */
803
+ format?: ExecFormat;
804
+ /** The bytes the format was identified from, for diagnostics. */
805
+ head?: Uint8Array;
750
806
  }
751
807
  interface MountEntry {
752
808
  device: string;
@@ -759,6 +815,8 @@ declare class Kernel {
759
815
  readonly vfs: Vfs;
760
816
  readonly procs: ProcessTable;
761
817
  readonly commands: CommandRegistry;
818
+ /** Handlers for executable files that are neither built-ins nor scripts. */
819
+ readonly formats: ExecFormatRegistry;
762
820
  readonly users: UserDatabase;
763
821
  readonly pod: Nodepod;
764
822
  readonly bootTime: number;
package/dist/index.d.ts CHANGED
@@ -613,6 +613,58 @@ interface ContextInit {
613
613
  }
614
614
  declare function createContext(init: ContextInit): ExecContext;
615
615
 
616
+ /**
617
+ * Executable format handlers — the container's `binfmt_misc`.
618
+ *
619
+ * The kernel knows how to dispatch two things by itself: a built-in command,
620
+ * and a text file with a `#!` line. Everything else is a binary, and the kernel
621
+ * deliberately knows nothing about what any particular binary is. Instead it
622
+ * sniffs the first bytes of the file and asks this registry who can run it.
623
+ *
624
+ * That indirection is the whole point. A format handler is registered at boot
625
+ * like a driver, so support for a new kind of executable is a handler, never a
626
+ * special case in `dispatch` and never a list of blessed program names. When a
627
+ * user drops a `wasm32-wasi` build of `jq` into `/usr/local/bin` and marks it
628
+ * executable, it runs — not because anything here has heard of `jq`, but
629
+ * because something here has heard of WebAssembly.
630
+ *
631
+ * A handler with no `run` is still worth registering: recognising an ELF binary
632
+ * well enough to say "this is an x86-64 Linux executable and nothing in this
633
+ * container can execute it" is far more use than `Exec format error`.
634
+ */
635
+
636
+ interface ExecFormat {
637
+ /** Short identifier, e.g. `wasi`. Shown by `file` and in diagnostics. */
638
+ readonly name: string;
639
+ /**
640
+ * Handlers are consulted in ascending priority, so a specific format can be
641
+ * tested before a broader one. Defaults to 50.
642
+ */
643
+ readonly priority?: number;
644
+ /** True when `head` is this format. Must not throw. */
645
+ matches(head: Uint8Array, path: string): boolean;
646
+ /** Human-readable description for `file`. */
647
+ describe?(head: Uint8Array, path: string): string;
648
+ /**
649
+ * Execute the file. `ctx.args` holds the arguments, exactly as for a
650
+ * built-in. Omit to register a format that is recognised but not runnable.
651
+ */
652
+ run?(ctx: ExecContext, path: string): Promise<number> | number;
653
+ /**
654
+ * Lines explaining why the format cannot run here, printed in place of
655
+ * `Exec format error`. Only consulted when `run` is absent.
656
+ */
657
+ explain?(head: Uint8Array, path: string): string[];
658
+ }
659
+ declare class ExecFormatRegistry {
660
+ private readonly formats;
661
+ register(format: ExecFormat): void;
662
+ registerAll(formats: ExecFormat[]): void;
663
+ /** The handler claiming `head`, or null when the bytes match nothing. */
664
+ match(head: Uint8Array, path: string): ExecFormat | null;
665
+ list(): ExecFormat[];
666
+ }
667
+
616
668
  /**
617
669
  * The container's network stack.
618
670
  *
@@ -738,7 +790,7 @@ interface RunResult {
738
790
  signal: string | null;
739
791
  timedOut: boolean;
740
792
  }
741
- type ExecutableKind = "builtin" | "script" | "unknown";
793
+ type ExecutableKind = "builtin" | "script" | "binary" | "unknown";
742
794
  interface ResolvedExecutable {
743
795
  kind: ExecutableKind;
744
796
  /** Absolute path of the file that was found. */
@@ -747,6 +799,10 @@ interface ResolvedExecutable {
747
799
  command?: Command;
748
800
  /** Interpreter argv from a `#!` line, when `kind === "script"`. */
749
801
  interpreter?: string[];
802
+ /** The registered handler for the file's magic, when `kind === "binary"`. */
803
+ format?: ExecFormat;
804
+ /** The bytes the format was identified from, for diagnostics. */
805
+ head?: Uint8Array;
750
806
  }
751
807
  interface MountEntry {
752
808
  device: string;
@@ -759,6 +815,8 @@ declare class Kernel {
759
815
  readonly vfs: Vfs;
760
816
  readonly procs: ProcessTable;
761
817
  readonly commands: CommandRegistry;
818
+ /** Handlers for executable files that are neither built-ins nor scripts. */
819
+ readonly formats: ExecFormatRegistry;
762
820
  readonly users: UserDatabase;
763
821
  readonly pod: Nodepod;
764
822
  readonly bootTime: number;