sandboxedjs 0.1.34 → 0.1.36

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
@@ -2642,6 +2642,13 @@ interface MirrorFs {
2642
2642
  }): void;
2643
2643
  unlinkSync?(path: string): void;
2644
2644
  rmdirSync?(path: string): void;
2645
+ readdirSync?(path: string): string[];
2646
+ readFileSync?(path: string): Uint8Array;
2647
+ lstatSync?(path: string): {
2648
+ isDirectory(): boolean;
2649
+ isSymbolicLink(): boolean;
2650
+ size?: number;
2651
+ };
2645
2652
  }
2646
2653
  /**
2647
2654
  * A `RuntimeVolume` that forwards every mutation to an optional mirror.
@@ -2665,6 +2672,22 @@ declare class MirroringVolume implements RuntimeVolume {
2665
2672
  detach(): void;
2666
2673
  /** Copy the whole subtree across. The only bulk operation that remains. */
2667
2674
  private seed;
2675
+ /**
2676
+ * Bring back what the mirrored engine wrote.
2677
+ *
2678
+ * The mirror exists because Rolldown's resolver reads through WASI rather
2679
+ * than through anything JavaScript can hand it — but Rolldown also *writes*
2680
+ * through WASI, so `vite build` leaves its output in the mirror and the
2681
+ * container sees an empty `dist/`. This is the return leg, and it is why the
2682
+ * mirror is no longer strictly one-way.
2683
+ *
2684
+ * Called when a process ends rather than on a timer: that is the moment a
2685
+ * build's output is complete, and a dev server — which serves from memory
2686
+ * and writes nothing — pays for it only once, at exit.
2687
+ */
2688
+ absorb(): void;
2689
+ /** `mkdir -p`, which the volume does not offer directly. */
2690
+ private ensureDirectory;
2668
2691
  /** Is this path inside the mirrored subtree? */
2669
2692
  private mirrored;
2670
2693
  /**
@@ -2905,6 +2928,243 @@ declare class CleanPackageInstaller implements RuntimePackageInstaller {
2905
2928
  }
2906
2929
  declare function extractNpmTarball(volume: RuntimeVolume, compressed: Uint8Array, destination: string): void;
2907
2930
 
2931
+ /**
2932
+ * Running a `wasm32-wasi` binary as an ordinary container process.
2933
+ *
2934
+ * Everything a guest sees is taken from the `ExecContext` it was dispatched
2935
+ * with — argv, environment, cwd, credentials, the three streams — so a wasm
2936
+ * binary is pipelineable, redirectable and killable exactly like `grep` is.
2937
+ * That is the whole point: `./tool.wasm < input | sort` has to work, or this
2938
+ * is a demo rather than a runtime.
2939
+ */
2940
+
2941
+ interface RunWasiOptions {
2942
+ /** Guest argv. Defaults to the context's own. */
2943
+ argv?: string[];
2944
+ /** Guest directory name → container path. */
2945
+ preopens?: Record<string, string>;
2946
+ /** Extra imports, for a module linked against more than WASI. */
2947
+ imports?: WebAssembly.Imports;
2948
+ }
2949
+ /** Load, instantiate and run a WebAssembly binary; returns its exit code. */
2950
+ declare function runWasi(ctx: ExecContext, bytes: Uint8Array, options?: RunWasiOptions): Promise<number>;
2951
+
2952
+ /**
2953
+ * A `wasi_snapshot_preview1` host, implemented against this container's kernel.
2954
+ *
2955
+ * The point of this file is that "run a native app" stops being a special
2956
+ * case. A program compiled to `wasm32-wasi` — by clang, Rust, Zig, Go's
2957
+ * `GOOS=wasip1`, TinyGo — asks for files, arguments, environment, clocks and
2958
+ * standard I/O through this one interface. Implement it against the VFS, the
2959
+ * process table and the container's streams, and those programs run beside the
2960
+ * coreutils with the same paths, the same permissions and the same pipes.
2961
+ *
2962
+ * Three constraints shape everything here.
2963
+ *
2964
+ * **Imports must be synchronous.** A WebAssembly import cannot await, but the
2965
+ * kernel's stdin is a promise. So stdin is drained *before* the module starts
2966
+ * (see `run.ts`) and served from a buffer; output streams are already
2967
+ * synchronous. This is the same trade the Python bridge makes, for the same
2968
+ * reason, and it is why an interactive `wasm` REPL reading a live terminal is
2969
+ * out of scope until stack-switching is available here.
2970
+ *
2971
+ * **The VFS has no file descriptors.** It reads and writes whole files. So an
2972
+ * open file is held as a buffer with a cursor, and written back on close, on
2973
+ * sync, and before any path-based call that could otherwise observe a stale
2974
+ * version of the file being written.
2975
+ *
2976
+ * **Capabilities are the VFS's, not a second model.** WASI's rights bitmask is
2977
+ * carried and reported, but enforcement is the kernel's own uid/gid check
2978
+ * running underneath every call. Preopens are enforced, because those *are*
2979
+ * meaningful here: a descriptor cannot escape the directory it was derived
2980
+ * from, so a caller that preopens only `/workspace` gets a program confined to
2981
+ * it.
2982
+ */
2983
+
2984
+ /** Standard input, already reduced to something readable without waiting. */
2985
+ interface WasiStdin {
2986
+ /** Up to `size` bytes; empty means end-of-file. Never blocks. */
2987
+ read(size: number): Uint8Array;
2988
+ /** Bytes that could be produced right now, for `poll_oneoff`. */
2989
+ readonly available: number;
2990
+ readonly isTTY: boolean;
2991
+ }
2992
+ interface WasiHostOptions {
2993
+ /** Full guest argv, `argv[0]` included. */
2994
+ argv: string[];
2995
+ env: Record<string, string>;
2996
+ vfs: Vfs;
2997
+ cred: Cred;
2998
+ /** Where relative guest paths resolve; published to the guest as `PWD`. */
2999
+ cwd: string;
3000
+ stdin: WasiStdin;
3001
+ stdout: OutputStream;
3002
+ stderr: OutputStream;
3003
+ /**
3004
+ * Guest path → container path. Defaults to the whole filesystem.
3005
+ *
3006
+ * Names are guest-visible *paths*, not labels: wasi-libc matches an open
3007
+ * against the longest preopen prefix, so a preopen called `.` claims every
3008
+ * absolute path as well and quietly turns `/work/out.txt` into
3009
+ * `work/out.txt` under whatever `.` points at. Relative paths need no
3010
+ * preopen of their own — libc joins them to `PWD` before it asks.
3011
+ */
3012
+ preopens?: Record<string, string>;
3013
+ now?: () => number;
3014
+ /** Monotonic nanosecond source, for `clock_time_get(MONOTONIC)`. */
3015
+ hrtime?: () => bigint;
3016
+ random?: (into: Uint8Array) => void;
3017
+ /** Blocking sleep. Returning early is allowed; the guest re-polls. */
3018
+ sleep?: (ms: number) => void;
3019
+ /** Consulted between sleep slices so a killed process stops waiting. */
3020
+ aborted?: () => boolean;
3021
+ }
3022
+ /** Thrown by `proc_exit` to unwind the guest's stack out to the runner. */
3023
+ declare class WasiExit extends Error {
3024
+ readonly code: number;
3025
+ constructor(code: number);
3026
+ }
3027
+ declare class WasiHost {
3028
+ private memory;
3029
+ private readonly fds;
3030
+ private nextFd;
3031
+ private readonly opts;
3032
+ private readonly startTime;
3033
+ /** Set once `proc_exit` has run, so the runner reports the guest's code. */
3034
+ exitCode: number | null;
3035
+ constructor(options: WasiHostOptions);
3036
+ /** Attach the instance's memory. Called before `_start`. */
3037
+ bind(instance: WebAssembly.Instance): void;
3038
+ /** Flush every buffered write. Called by the runner when the guest ends. */
3039
+ flushAll(): void;
3040
+ /**
3041
+ * `wasi_snapshot_preview1`.
3042
+ *
3043
+ * Every entry returns an errno rather than throwing: a JavaScript exception
3044
+ * crossing back into WebAssembly traps the instance, which turns a missing
3045
+ * file into an unrecoverable crash instead of the `ENOENT` the guest is
3046
+ * written to handle. `guard` is what enforces that.
3047
+ */
3048
+ get wasiImport(): Record<string, (...args: never[]) => unknown>;
3049
+ /**
3050
+ * `wasi_unstable`, the preview0 name older toolchains still emit.
3051
+ *
3052
+ * Identical but for `fd_seek`, whose `whence` values were reordered before
3053
+ * preview1 was frozen. Aliasing the table without this correction is a
3054
+ * popular bug: every seek in an old binary lands somewhere plausible and
3055
+ * wrong.
3056
+ */
3057
+ get wasiUnstableImport(): Record<string, (...args: never[]) => unknown>;
3058
+ private get view();
3059
+ private get bytes();
3060
+ private readString;
3061
+ /** The scatter/gather list `fd_read` and `fd_write` are given. */
3062
+ private iovecs;
3063
+ /**
3064
+ * Turn anything thrown inside a syscall into an errno.
3065
+ *
3066
+ * `WasiExit` is re-thrown on purpose: it is the guest unwinding its own
3067
+ * stack, not a failure to be reported through a return value.
3068
+ */
3069
+ private guard;
3070
+ private get;
3071
+ private dir;
3072
+ private file;
3073
+ /**
3074
+ * Resolve a guest path against a directory descriptor.
3075
+ *
3076
+ * The confinement check is the one place preopens are enforced: a path that
3077
+ * climbs out of the directory the descriptor was derived from is
3078
+ * `ENOTCAPABLE`, which is exactly the error a capability-oriented guest
3079
+ * expects and knows how to report.
3080
+ */
3081
+ private resolveAt;
3082
+ private allocate;
3083
+ /**
3084
+ * Push a buffered file back to the VFS.
3085
+ *
3086
+ * Called before every path-based call as well as on close, so a guest that
3087
+ * writes a file and then stats or reopens it by name sees what it wrote —
3088
+ * the alternative is a stale read that looks like data loss.
3089
+ */
3090
+ private writeBack;
3091
+ private syncPaths;
3092
+ private args_get;
3093
+ private args_sizes_get;
3094
+ private get envStrings();
3095
+ private environ_get;
3096
+ private environ_sizes_get;
3097
+ private writeStringVector;
3098
+ private writeVectorSizes;
3099
+ private clock_res_get;
3100
+ private clock_time_get;
3101
+ private clockNow;
3102
+ private random_get;
3103
+ private fd_read;
3104
+ private fd_pread;
3105
+ private fd_write;
3106
+ private fd_pwrite;
3107
+ private fd_seek;
3108
+ private fd_tell;
3109
+ private fd_close;
3110
+ private fd_sync;
3111
+ private fd_renumber;
3112
+ private fd_allocate;
3113
+ private fd_filestat_set_size;
3114
+ private fd_fdstat_get;
3115
+ private fd_fdstat_set_flags;
3116
+ private fd_filestat_get;
3117
+ private fd_filestat_set_times;
3118
+ private path_filestat_get;
3119
+ private path_filestat_set_times;
3120
+ private setTimes;
3121
+ private writeFilestat;
3122
+ private fd_prestat_get;
3123
+ private fd_prestat_dir_name;
3124
+ private path_open;
3125
+ private fd_readdir;
3126
+ private path_create_directory;
3127
+ private path_remove_directory;
3128
+ private path_unlink_file;
3129
+ private path_rename;
3130
+ private path_symlink;
3131
+ private path_link;
3132
+ private path_readlink;
3133
+ /**
3134
+ * `poll_oneoff`, which is how a WASI guest sleeps and how it waits on I/O.
3135
+ *
3136
+ * Files and the standard streams are always ready here — nothing in this
3137
+ * container can leave a read pending, since stdin was drained before the
3138
+ * guest started. That leaves the clock, which is the case that matters:
3139
+ * `sleep()` compiles to a lone clock subscription, and it is honoured by
3140
+ * actually waiting, in slices, so that killing the process interrupts it.
3141
+ */
3142
+ private poll_oneoff;
3143
+ private bytesLeft;
3144
+ /** Wait in slices so that a `SIGKILL` does not have to outlast the sleep. */
3145
+ private sleepInterruptibly;
3146
+ }
3147
+ /** An errno on its way back to the guest, rather than a JavaScript failure. */
3148
+ declare class WasiError extends Error {
3149
+ readonly errno: number;
3150
+ constructor(errno: number);
3151
+ }
3152
+
3153
+ /** Whether `bytes` begins with the WebAssembly magic number. */
3154
+ declare function isWasmBinary(bytes: Uint8Array): boolean;
3155
+
3156
+ /**
3157
+ * `wasi` — the interpreter that stands behind every `.wasm` file in `$PATH`.
3158
+ *
3159
+ * It is invoked two ways, and they are the same code path. A user can run
3160
+ * `wasi build/tool.wasm --flag`, or they can `chmod +x tool.wasm && ./tool.wasm
3161
+ * --flag` and let the kernel dispatch it here the way it dispatches a `#!`
3162
+ * script. The second is the one that matters: it is what makes a compiled
3163
+ * binary indistinguishable from any other program on the system.
3164
+ */
3165
+
3166
+ declare const wasi: Command;
3167
+
2908
3168
  /**
2909
3169
  * Starting the guest Worker, in whichever environment the host happens to be.
2910
3170
  *
@@ -3009,4 +3269,4 @@ declare function renderInto(box: Container, element: HTMLElement, options?: {
3009
3269
  * ```
3010
3270
  */
3011
3271
 
3012
- 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, type Preview, type PreviewOptions, 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 WorkerRuntimeOptions, WorkerRuntimePod, type WriteOptions, allCommands, applyChmod, braceExpand, buildRootfs, builtinNames, captureStdio, configureCPython, configurePython, createChildProcessModule, createContainer, createContext, createCoreModules, createPreview, 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, renderInto, resetPidCounter, shellQuote, startRuntimeWorker, strerror, syncChannelSupported, transformEsm, unameInfo };
3272
+ 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, type Preview, type PreviewOptions, Process, type ProcessKind, type ProcessOptions, type ProcessState, ProcessTable, type PythonOptions, ROOT_CRED, type ResolvedExecutable, type RootfsOptions, type RunOptions, type RunResult, type RunWasiOptions, 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, WasiError, WasiExit, WasiHost, type WasiHostOptions, type WasiStdin, type WorkerRuntimeOptions, WorkerRuntimePod, type WriteOptions, allCommands, applyChmod, braceExpand, buildRootfs, builtinNames, captureStdio, configureCPython, configurePython, createChildProcessModule, createContainer, createContext, createCoreModules, createPreview, createContainer as default, defineCommand, evalArith, exitCodeForSignal, expandPrompt, expandWord, expandWords, extractNpmTarball, fnmatch, formatMode, getBuiltin, glob, globToRegex, hasMagic, installUserland, isBuiltinName, isCPythonAvailable, isPythonAvailable, isSysError, isWasmBinary, looksLikeEsm, makeCred, normalizeSignal, octalMode, parse as parseShell, parseUmask, path as posixPath, renderInto, resetPidCounter, runWasi, shellQuote, startRuntimeWorker, strerror, syncChannelSupported, transformEsm, unameInfo, wasi as wasiCommand };
package/dist/index.d.ts CHANGED
@@ -2642,6 +2642,13 @@ interface MirrorFs {
2642
2642
  }): void;
2643
2643
  unlinkSync?(path: string): void;
2644
2644
  rmdirSync?(path: string): void;
2645
+ readdirSync?(path: string): string[];
2646
+ readFileSync?(path: string): Uint8Array;
2647
+ lstatSync?(path: string): {
2648
+ isDirectory(): boolean;
2649
+ isSymbolicLink(): boolean;
2650
+ size?: number;
2651
+ };
2645
2652
  }
2646
2653
  /**
2647
2654
  * A `RuntimeVolume` that forwards every mutation to an optional mirror.
@@ -2665,6 +2672,22 @@ declare class MirroringVolume implements RuntimeVolume {
2665
2672
  detach(): void;
2666
2673
  /** Copy the whole subtree across. The only bulk operation that remains. */
2667
2674
  private seed;
2675
+ /**
2676
+ * Bring back what the mirrored engine wrote.
2677
+ *
2678
+ * The mirror exists because Rolldown's resolver reads through WASI rather
2679
+ * than through anything JavaScript can hand it — but Rolldown also *writes*
2680
+ * through WASI, so `vite build` leaves its output in the mirror and the
2681
+ * container sees an empty `dist/`. This is the return leg, and it is why the
2682
+ * mirror is no longer strictly one-way.
2683
+ *
2684
+ * Called when a process ends rather than on a timer: that is the moment a
2685
+ * build's output is complete, and a dev server — which serves from memory
2686
+ * and writes nothing — pays for it only once, at exit.
2687
+ */
2688
+ absorb(): void;
2689
+ /** `mkdir -p`, which the volume does not offer directly. */
2690
+ private ensureDirectory;
2668
2691
  /** Is this path inside the mirrored subtree? */
2669
2692
  private mirrored;
2670
2693
  /**
@@ -2905,6 +2928,243 @@ declare class CleanPackageInstaller implements RuntimePackageInstaller {
2905
2928
  }
2906
2929
  declare function extractNpmTarball(volume: RuntimeVolume, compressed: Uint8Array, destination: string): void;
2907
2930
 
2931
+ /**
2932
+ * Running a `wasm32-wasi` binary as an ordinary container process.
2933
+ *
2934
+ * Everything a guest sees is taken from the `ExecContext` it was dispatched
2935
+ * with — argv, environment, cwd, credentials, the three streams — so a wasm
2936
+ * binary is pipelineable, redirectable and killable exactly like `grep` is.
2937
+ * That is the whole point: `./tool.wasm < input | sort` has to work, or this
2938
+ * is a demo rather than a runtime.
2939
+ */
2940
+
2941
+ interface RunWasiOptions {
2942
+ /** Guest argv. Defaults to the context's own. */
2943
+ argv?: string[];
2944
+ /** Guest directory name → container path. */
2945
+ preopens?: Record<string, string>;
2946
+ /** Extra imports, for a module linked against more than WASI. */
2947
+ imports?: WebAssembly.Imports;
2948
+ }
2949
+ /** Load, instantiate and run a WebAssembly binary; returns its exit code. */
2950
+ declare function runWasi(ctx: ExecContext, bytes: Uint8Array, options?: RunWasiOptions): Promise<number>;
2951
+
2952
+ /**
2953
+ * A `wasi_snapshot_preview1` host, implemented against this container's kernel.
2954
+ *
2955
+ * The point of this file is that "run a native app" stops being a special
2956
+ * case. A program compiled to `wasm32-wasi` — by clang, Rust, Zig, Go's
2957
+ * `GOOS=wasip1`, TinyGo — asks for files, arguments, environment, clocks and
2958
+ * standard I/O through this one interface. Implement it against the VFS, the
2959
+ * process table and the container's streams, and those programs run beside the
2960
+ * coreutils with the same paths, the same permissions and the same pipes.
2961
+ *
2962
+ * Three constraints shape everything here.
2963
+ *
2964
+ * **Imports must be synchronous.** A WebAssembly import cannot await, but the
2965
+ * kernel's stdin is a promise. So stdin is drained *before* the module starts
2966
+ * (see `run.ts`) and served from a buffer; output streams are already
2967
+ * synchronous. This is the same trade the Python bridge makes, for the same
2968
+ * reason, and it is why an interactive `wasm` REPL reading a live terminal is
2969
+ * out of scope until stack-switching is available here.
2970
+ *
2971
+ * **The VFS has no file descriptors.** It reads and writes whole files. So an
2972
+ * open file is held as a buffer with a cursor, and written back on close, on
2973
+ * sync, and before any path-based call that could otherwise observe a stale
2974
+ * version of the file being written.
2975
+ *
2976
+ * **Capabilities are the VFS's, not a second model.** WASI's rights bitmask is
2977
+ * carried and reported, but enforcement is the kernel's own uid/gid check
2978
+ * running underneath every call. Preopens are enforced, because those *are*
2979
+ * meaningful here: a descriptor cannot escape the directory it was derived
2980
+ * from, so a caller that preopens only `/workspace` gets a program confined to
2981
+ * it.
2982
+ */
2983
+
2984
+ /** Standard input, already reduced to something readable without waiting. */
2985
+ interface WasiStdin {
2986
+ /** Up to `size` bytes; empty means end-of-file. Never blocks. */
2987
+ read(size: number): Uint8Array;
2988
+ /** Bytes that could be produced right now, for `poll_oneoff`. */
2989
+ readonly available: number;
2990
+ readonly isTTY: boolean;
2991
+ }
2992
+ interface WasiHostOptions {
2993
+ /** Full guest argv, `argv[0]` included. */
2994
+ argv: string[];
2995
+ env: Record<string, string>;
2996
+ vfs: Vfs;
2997
+ cred: Cred;
2998
+ /** Where relative guest paths resolve; published to the guest as `PWD`. */
2999
+ cwd: string;
3000
+ stdin: WasiStdin;
3001
+ stdout: OutputStream;
3002
+ stderr: OutputStream;
3003
+ /**
3004
+ * Guest path → container path. Defaults to the whole filesystem.
3005
+ *
3006
+ * Names are guest-visible *paths*, not labels: wasi-libc matches an open
3007
+ * against the longest preopen prefix, so a preopen called `.` claims every
3008
+ * absolute path as well and quietly turns `/work/out.txt` into
3009
+ * `work/out.txt` under whatever `.` points at. Relative paths need no
3010
+ * preopen of their own — libc joins them to `PWD` before it asks.
3011
+ */
3012
+ preopens?: Record<string, string>;
3013
+ now?: () => number;
3014
+ /** Monotonic nanosecond source, for `clock_time_get(MONOTONIC)`. */
3015
+ hrtime?: () => bigint;
3016
+ random?: (into: Uint8Array) => void;
3017
+ /** Blocking sleep. Returning early is allowed; the guest re-polls. */
3018
+ sleep?: (ms: number) => void;
3019
+ /** Consulted between sleep slices so a killed process stops waiting. */
3020
+ aborted?: () => boolean;
3021
+ }
3022
+ /** Thrown by `proc_exit` to unwind the guest's stack out to the runner. */
3023
+ declare class WasiExit extends Error {
3024
+ readonly code: number;
3025
+ constructor(code: number);
3026
+ }
3027
+ declare class WasiHost {
3028
+ private memory;
3029
+ private readonly fds;
3030
+ private nextFd;
3031
+ private readonly opts;
3032
+ private readonly startTime;
3033
+ /** Set once `proc_exit` has run, so the runner reports the guest's code. */
3034
+ exitCode: number | null;
3035
+ constructor(options: WasiHostOptions);
3036
+ /** Attach the instance's memory. Called before `_start`. */
3037
+ bind(instance: WebAssembly.Instance): void;
3038
+ /** Flush every buffered write. Called by the runner when the guest ends. */
3039
+ flushAll(): void;
3040
+ /**
3041
+ * `wasi_snapshot_preview1`.
3042
+ *
3043
+ * Every entry returns an errno rather than throwing: a JavaScript exception
3044
+ * crossing back into WebAssembly traps the instance, which turns a missing
3045
+ * file into an unrecoverable crash instead of the `ENOENT` the guest is
3046
+ * written to handle. `guard` is what enforces that.
3047
+ */
3048
+ get wasiImport(): Record<string, (...args: never[]) => unknown>;
3049
+ /**
3050
+ * `wasi_unstable`, the preview0 name older toolchains still emit.
3051
+ *
3052
+ * Identical but for `fd_seek`, whose `whence` values were reordered before
3053
+ * preview1 was frozen. Aliasing the table without this correction is a
3054
+ * popular bug: every seek in an old binary lands somewhere plausible and
3055
+ * wrong.
3056
+ */
3057
+ get wasiUnstableImport(): Record<string, (...args: never[]) => unknown>;
3058
+ private get view();
3059
+ private get bytes();
3060
+ private readString;
3061
+ /** The scatter/gather list `fd_read` and `fd_write` are given. */
3062
+ private iovecs;
3063
+ /**
3064
+ * Turn anything thrown inside a syscall into an errno.
3065
+ *
3066
+ * `WasiExit` is re-thrown on purpose: it is the guest unwinding its own
3067
+ * stack, not a failure to be reported through a return value.
3068
+ */
3069
+ private guard;
3070
+ private get;
3071
+ private dir;
3072
+ private file;
3073
+ /**
3074
+ * Resolve a guest path against a directory descriptor.
3075
+ *
3076
+ * The confinement check is the one place preopens are enforced: a path that
3077
+ * climbs out of the directory the descriptor was derived from is
3078
+ * `ENOTCAPABLE`, which is exactly the error a capability-oriented guest
3079
+ * expects and knows how to report.
3080
+ */
3081
+ private resolveAt;
3082
+ private allocate;
3083
+ /**
3084
+ * Push a buffered file back to the VFS.
3085
+ *
3086
+ * Called before every path-based call as well as on close, so a guest that
3087
+ * writes a file and then stats or reopens it by name sees what it wrote —
3088
+ * the alternative is a stale read that looks like data loss.
3089
+ */
3090
+ private writeBack;
3091
+ private syncPaths;
3092
+ private args_get;
3093
+ private args_sizes_get;
3094
+ private get envStrings();
3095
+ private environ_get;
3096
+ private environ_sizes_get;
3097
+ private writeStringVector;
3098
+ private writeVectorSizes;
3099
+ private clock_res_get;
3100
+ private clock_time_get;
3101
+ private clockNow;
3102
+ private random_get;
3103
+ private fd_read;
3104
+ private fd_pread;
3105
+ private fd_write;
3106
+ private fd_pwrite;
3107
+ private fd_seek;
3108
+ private fd_tell;
3109
+ private fd_close;
3110
+ private fd_sync;
3111
+ private fd_renumber;
3112
+ private fd_allocate;
3113
+ private fd_filestat_set_size;
3114
+ private fd_fdstat_get;
3115
+ private fd_fdstat_set_flags;
3116
+ private fd_filestat_get;
3117
+ private fd_filestat_set_times;
3118
+ private path_filestat_get;
3119
+ private path_filestat_set_times;
3120
+ private setTimes;
3121
+ private writeFilestat;
3122
+ private fd_prestat_get;
3123
+ private fd_prestat_dir_name;
3124
+ private path_open;
3125
+ private fd_readdir;
3126
+ private path_create_directory;
3127
+ private path_remove_directory;
3128
+ private path_unlink_file;
3129
+ private path_rename;
3130
+ private path_symlink;
3131
+ private path_link;
3132
+ private path_readlink;
3133
+ /**
3134
+ * `poll_oneoff`, which is how a WASI guest sleeps and how it waits on I/O.
3135
+ *
3136
+ * Files and the standard streams are always ready here — nothing in this
3137
+ * container can leave a read pending, since stdin was drained before the
3138
+ * guest started. That leaves the clock, which is the case that matters:
3139
+ * `sleep()` compiles to a lone clock subscription, and it is honoured by
3140
+ * actually waiting, in slices, so that killing the process interrupts it.
3141
+ */
3142
+ private poll_oneoff;
3143
+ private bytesLeft;
3144
+ /** Wait in slices so that a `SIGKILL` does not have to outlast the sleep. */
3145
+ private sleepInterruptibly;
3146
+ }
3147
+ /** An errno on its way back to the guest, rather than a JavaScript failure. */
3148
+ declare class WasiError extends Error {
3149
+ readonly errno: number;
3150
+ constructor(errno: number);
3151
+ }
3152
+
3153
+ /** Whether `bytes` begins with the WebAssembly magic number. */
3154
+ declare function isWasmBinary(bytes: Uint8Array): boolean;
3155
+
3156
+ /**
3157
+ * `wasi` — the interpreter that stands behind every `.wasm` file in `$PATH`.
3158
+ *
3159
+ * It is invoked two ways, and they are the same code path. A user can run
3160
+ * `wasi build/tool.wasm --flag`, or they can `chmod +x tool.wasm && ./tool.wasm
3161
+ * --flag` and let the kernel dispatch it here the way it dispatches a `#!`
3162
+ * script. The second is the one that matters: it is what makes a compiled
3163
+ * binary indistinguishable from any other program on the system.
3164
+ */
3165
+
3166
+ declare const wasi: Command;
3167
+
2908
3168
  /**
2909
3169
  * Starting the guest Worker, in whichever environment the host happens to be.
2910
3170
  *
@@ -3009,4 +3269,4 @@ declare function renderInto(box: Container, element: HTMLElement, options?: {
3009
3269
  * ```
3010
3270
  */
3011
3271
 
3012
- 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, type Preview, type PreviewOptions, 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 WorkerRuntimeOptions, WorkerRuntimePod, type WriteOptions, allCommands, applyChmod, braceExpand, buildRootfs, builtinNames, captureStdio, configureCPython, configurePython, createChildProcessModule, createContainer, createContext, createCoreModules, createPreview, 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, renderInto, resetPidCounter, shellQuote, startRuntimeWorker, strerror, syncChannelSupported, transformEsm, unameInfo };
3272
+ 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, type Preview, type PreviewOptions, Process, type ProcessKind, type ProcessOptions, type ProcessState, ProcessTable, type PythonOptions, ROOT_CRED, type ResolvedExecutable, type RootfsOptions, type RunOptions, type RunResult, type RunWasiOptions, 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, WasiError, WasiExit, WasiHost, type WasiHostOptions, type WasiStdin, type WorkerRuntimeOptions, WorkerRuntimePod, type WriteOptions, allCommands, applyChmod, braceExpand, buildRootfs, builtinNames, captureStdio, configureCPython, configurePython, createChildProcessModule, createContainer, createContext, createCoreModules, createPreview, createContainer as default, defineCommand, evalArith, exitCodeForSignal, expandPrompt, expandWord, expandWords, extractNpmTarball, fnmatch, formatMode, getBuiltin, glob, globToRegex, hasMagic, installUserland, isBuiltinName, isCPythonAvailable, isPythonAvailable, isSysError, isWasmBinary, looksLikeEsm, makeCred, normalizeSignal, octalMode, parse as parseShell, parseUmask, path as posixPath, renderInto, resetPidCounter, runWasi, shellQuote, startRuntimeWorker, strerror, syncChannelSupported, transformEsm, unameInfo, wasi as wasiCommand };