sandboxedjs 0.1.34 → 0.1.35
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/README.md +42 -0
- package/bin/sandboxedjs.mjs +3 -1
- package/dist/index.cjs +1130 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +238 -1
- package/dist/index.d.ts +238 -1
- package/dist/index.js +1125 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -2905,6 +2905,243 @@ declare class CleanPackageInstaller implements RuntimePackageInstaller {
|
|
|
2905
2905
|
}
|
|
2906
2906
|
declare function extractNpmTarball(volume: RuntimeVolume, compressed: Uint8Array, destination: string): void;
|
|
2907
2907
|
|
|
2908
|
+
/**
|
|
2909
|
+
* Running a `wasm32-wasi` binary as an ordinary container process.
|
|
2910
|
+
*
|
|
2911
|
+
* Everything a guest sees is taken from the `ExecContext` it was dispatched
|
|
2912
|
+
* with — argv, environment, cwd, credentials, the three streams — so a wasm
|
|
2913
|
+
* binary is pipelineable, redirectable and killable exactly like `grep` is.
|
|
2914
|
+
* That is the whole point: `./tool.wasm < input | sort` has to work, or this
|
|
2915
|
+
* is a demo rather than a runtime.
|
|
2916
|
+
*/
|
|
2917
|
+
|
|
2918
|
+
interface RunWasiOptions {
|
|
2919
|
+
/** Guest argv. Defaults to the context's own. */
|
|
2920
|
+
argv?: string[];
|
|
2921
|
+
/** Guest directory name → container path. */
|
|
2922
|
+
preopens?: Record<string, string>;
|
|
2923
|
+
/** Extra imports, for a module linked against more than WASI. */
|
|
2924
|
+
imports?: WebAssembly.Imports;
|
|
2925
|
+
}
|
|
2926
|
+
/** Load, instantiate and run a WebAssembly binary; returns its exit code. */
|
|
2927
|
+
declare function runWasi(ctx: ExecContext, bytes: Uint8Array, options?: RunWasiOptions): Promise<number>;
|
|
2928
|
+
|
|
2929
|
+
/**
|
|
2930
|
+
* A `wasi_snapshot_preview1` host, implemented against this container's kernel.
|
|
2931
|
+
*
|
|
2932
|
+
* The point of this file is that "run a native app" stops being a special
|
|
2933
|
+
* case. A program compiled to `wasm32-wasi` — by clang, Rust, Zig, Go's
|
|
2934
|
+
* `GOOS=wasip1`, TinyGo — asks for files, arguments, environment, clocks and
|
|
2935
|
+
* standard I/O through this one interface. Implement it against the VFS, the
|
|
2936
|
+
* process table and the container's streams, and those programs run beside the
|
|
2937
|
+
* coreutils with the same paths, the same permissions and the same pipes.
|
|
2938
|
+
*
|
|
2939
|
+
* Three constraints shape everything here.
|
|
2940
|
+
*
|
|
2941
|
+
* **Imports must be synchronous.** A WebAssembly import cannot await, but the
|
|
2942
|
+
* kernel's stdin is a promise. So stdin is drained *before* the module starts
|
|
2943
|
+
* (see `run.ts`) and served from a buffer; output streams are already
|
|
2944
|
+
* synchronous. This is the same trade the Python bridge makes, for the same
|
|
2945
|
+
* reason, and it is why an interactive `wasm` REPL reading a live terminal is
|
|
2946
|
+
* out of scope until stack-switching is available here.
|
|
2947
|
+
*
|
|
2948
|
+
* **The VFS has no file descriptors.** It reads and writes whole files. So an
|
|
2949
|
+
* open file is held as a buffer with a cursor, and written back on close, on
|
|
2950
|
+
* sync, and before any path-based call that could otherwise observe a stale
|
|
2951
|
+
* version of the file being written.
|
|
2952
|
+
*
|
|
2953
|
+
* **Capabilities are the VFS's, not a second model.** WASI's rights bitmask is
|
|
2954
|
+
* carried and reported, but enforcement is the kernel's own uid/gid check
|
|
2955
|
+
* running underneath every call. Preopens are enforced, because those *are*
|
|
2956
|
+
* meaningful here: a descriptor cannot escape the directory it was derived
|
|
2957
|
+
* from, so a caller that preopens only `/workspace` gets a program confined to
|
|
2958
|
+
* it.
|
|
2959
|
+
*/
|
|
2960
|
+
|
|
2961
|
+
/** Standard input, already reduced to something readable without waiting. */
|
|
2962
|
+
interface WasiStdin {
|
|
2963
|
+
/** Up to `size` bytes; empty means end-of-file. Never blocks. */
|
|
2964
|
+
read(size: number): Uint8Array;
|
|
2965
|
+
/** Bytes that could be produced right now, for `poll_oneoff`. */
|
|
2966
|
+
readonly available: number;
|
|
2967
|
+
readonly isTTY: boolean;
|
|
2968
|
+
}
|
|
2969
|
+
interface WasiHostOptions {
|
|
2970
|
+
/** Full guest argv, `argv[0]` included. */
|
|
2971
|
+
argv: string[];
|
|
2972
|
+
env: Record<string, string>;
|
|
2973
|
+
vfs: Vfs;
|
|
2974
|
+
cred: Cred;
|
|
2975
|
+
/** Where relative guest paths resolve; published to the guest as `PWD`. */
|
|
2976
|
+
cwd: string;
|
|
2977
|
+
stdin: WasiStdin;
|
|
2978
|
+
stdout: OutputStream;
|
|
2979
|
+
stderr: OutputStream;
|
|
2980
|
+
/**
|
|
2981
|
+
* Guest path → container path. Defaults to the whole filesystem.
|
|
2982
|
+
*
|
|
2983
|
+
* Names are guest-visible *paths*, not labels: wasi-libc matches an open
|
|
2984
|
+
* against the longest preopen prefix, so a preopen called `.` claims every
|
|
2985
|
+
* absolute path as well and quietly turns `/work/out.txt` into
|
|
2986
|
+
* `work/out.txt` under whatever `.` points at. Relative paths need no
|
|
2987
|
+
* preopen of their own — libc joins them to `PWD` before it asks.
|
|
2988
|
+
*/
|
|
2989
|
+
preopens?: Record<string, string>;
|
|
2990
|
+
now?: () => number;
|
|
2991
|
+
/** Monotonic nanosecond source, for `clock_time_get(MONOTONIC)`. */
|
|
2992
|
+
hrtime?: () => bigint;
|
|
2993
|
+
random?: (into: Uint8Array) => void;
|
|
2994
|
+
/** Blocking sleep. Returning early is allowed; the guest re-polls. */
|
|
2995
|
+
sleep?: (ms: number) => void;
|
|
2996
|
+
/** Consulted between sleep slices so a killed process stops waiting. */
|
|
2997
|
+
aborted?: () => boolean;
|
|
2998
|
+
}
|
|
2999
|
+
/** Thrown by `proc_exit` to unwind the guest's stack out to the runner. */
|
|
3000
|
+
declare class WasiExit extends Error {
|
|
3001
|
+
readonly code: number;
|
|
3002
|
+
constructor(code: number);
|
|
3003
|
+
}
|
|
3004
|
+
declare class WasiHost {
|
|
3005
|
+
private memory;
|
|
3006
|
+
private readonly fds;
|
|
3007
|
+
private nextFd;
|
|
3008
|
+
private readonly opts;
|
|
3009
|
+
private readonly startTime;
|
|
3010
|
+
/** Set once `proc_exit` has run, so the runner reports the guest's code. */
|
|
3011
|
+
exitCode: number | null;
|
|
3012
|
+
constructor(options: WasiHostOptions);
|
|
3013
|
+
/** Attach the instance's memory. Called before `_start`. */
|
|
3014
|
+
bind(instance: WebAssembly.Instance): void;
|
|
3015
|
+
/** Flush every buffered write. Called by the runner when the guest ends. */
|
|
3016
|
+
flushAll(): void;
|
|
3017
|
+
/**
|
|
3018
|
+
* `wasi_snapshot_preview1`.
|
|
3019
|
+
*
|
|
3020
|
+
* Every entry returns an errno rather than throwing: a JavaScript exception
|
|
3021
|
+
* crossing back into WebAssembly traps the instance, which turns a missing
|
|
3022
|
+
* file into an unrecoverable crash instead of the `ENOENT` the guest is
|
|
3023
|
+
* written to handle. `guard` is what enforces that.
|
|
3024
|
+
*/
|
|
3025
|
+
get wasiImport(): Record<string, (...args: never[]) => unknown>;
|
|
3026
|
+
/**
|
|
3027
|
+
* `wasi_unstable`, the preview0 name older toolchains still emit.
|
|
3028
|
+
*
|
|
3029
|
+
* Identical but for `fd_seek`, whose `whence` values were reordered before
|
|
3030
|
+
* preview1 was frozen. Aliasing the table without this correction is a
|
|
3031
|
+
* popular bug: every seek in an old binary lands somewhere plausible and
|
|
3032
|
+
* wrong.
|
|
3033
|
+
*/
|
|
3034
|
+
get wasiUnstableImport(): Record<string, (...args: never[]) => unknown>;
|
|
3035
|
+
private get view();
|
|
3036
|
+
private get bytes();
|
|
3037
|
+
private readString;
|
|
3038
|
+
/** The scatter/gather list `fd_read` and `fd_write` are given. */
|
|
3039
|
+
private iovecs;
|
|
3040
|
+
/**
|
|
3041
|
+
* Turn anything thrown inside a syscall into an errno.
|
|
3042
|
+
*
|
|
3043
|
+
* `WasiExit` is re-thrown on purpose: it is the guest unwinding its own
|
|
3044
|
+
* stack, not a failure to be reported through a return value.
|
|
3045
|
+
*/
|
|
3046
|
+
private guard;
|
|
3047
|
+
private get;
|
|
3048
|
+
private dir;
|
|
3049
|
+
private file;
|
|
3050
|
+
/**
|
|
3051
|
+
* Resolve a guest path against a directory descriptor.
|
|
3052
|
+
*
|
|
3053
|
+
* The confinement check is the one place preopens are enforced: a path that
|
|
3054
|
+
* climbs out of the directory the descriptor was derived from is
|
|
3055
|
+
* `ENOTCAPABLE`, which is exactly the error a capability-oriented guest
|
|
3056
|
+
* expects and knows how to report.
|
|
3057
|
+
*/
|
|
3058
|
+
private resolveAt;
|
|
3059
|
+
private allocate;
|
|
3060
|
+
/**
|
|
3061
|
+
* Push a buffered file back to the VFS.
|
|
3062
|
+
*
|
|
3063
|
+
* Called before every path-based call as well as on close, so a guest that
|
|
3064
|
+
* writes a file and then stats or reopens it by name sees what it wrote —
|
|
3065
|
+
* the alternative is a stale read that looks like data loss.
|
|
3066
|
+
*/
|
|
3067
|
+
private writeBack;
|
|
3068
|
+
private syncPaths;
|
|
3069
|
+
private args_get;
|
|
3070
|
+
private args_sizes_get;
|
|
3071
|
+
private get envStrings();
|
|
3072
|
+
private environ_get;
|
|
3073
|
+
private environ_sizes_get;
|
|
3074
|
+
private writeStringVector;
|
|
3075
|
+
private writeVectorSizes;
|
|
3076
|
+
private clock_res_get;
|
|
3077
|
+
private clock_time_get;
|
|
3078
|
+
private clockNow;
|
|
3079
|
+
private random_get;
|
|
3080
|
+
private fd_read;
|
|
3081
|
+
private fd_pread;
|
|
3082
|
+
private fd_write;
|
|
3083
|
+
private fd_pwrite;
|
|
3084
|
+
private fd_seek;
|
|
3085
|
+
private fd_tell;
|
|
3086
|
+
private fd_close;
|
|
3087
|
+
private fd_sync;
|
|
3088
|
+
private fd_renumber;
|
|
3089
|
+
private fd_allocate;
|
|
3090
|
+
private fd_filestat_set_size;
|
|
3091
|
+
private fd_fdstat_get;
|
|
3092
|
+
private fd_fdstat_set_flags;
|
|
3093
|
+
private fd_filestat_get;
|
|
3094
|
+
private fd_filestat_set_times;
|
|
3095
|
+
private path_filestat_get;
|
|
3096
|
+
private path_filestat_set_times;
|
|
3097
|
+
private setTimes;
|
|
3098
|
+
private writeFilestat;
|
|
3099
|
+
private fd_prestat_get;
|
|
3100
|
+
private fd_prestat_dir_name;
|
|
3101
|
+
private path_open;
|
|
3102
|
+
private fd_readdir;
|
|
3103
|
+
private path_create_directory;
|
|
3104
|
+
private path_remove_directory;
|
|
3105
|
+
private path_unlink_file;
|
|
3106
|
+
private path_rename;
|
|
3107
|
+
private path_symlink;
|
|
3108
|
+
private path_link;
|
|
3109
|
+
private path_readlink;
|
|
3110
|
+
/**
|
|
3111
|
+
* `poll_oneoff`, which is how a WASI guest sleeps and how it waits on I/O.
|
|
3112
|
+
*
|
|
3113
|
+
* Files and the standard streams are always ready here — nothing in this
|
|
3114
|
+
* container can leave a read pending, since stdin was drained before the
|
|
3115
|
+
* guest started. That leaves the clock, which is the case that matters:
|
|
3116
|
+
* `sleep()` compiles to a lone clock subscription, and it is honoured by
|
|
3117
|
+
* actually waiting, in slices, so that killing the process interrupts it.
|
|
3118
|
+
*/
|
|
3119
|
+
private poll_oneoff;
|
|
3120
|
+
private bytesLeft;
|
|
3121
|
+
/** Wait in slices so that a `SIGKILL` does not have to outlast the sleep. */
|
|
3122
|
+
private sleepInterruptibly;
|
|
3123
|
+
}
|
|
3124
|
+
/** An errno on its way back to the guest, rather than a JavaScript failure. */
|
|
3125
|
+
declare class WasiError extends Error {
|
|
3126
|
+
readonly errno: number;
|
|
3127
|
+
constructor(errno: number);
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
/** Whether `bytes` begins with the WebAssembly magic number. */
|
|
3131
|
+
declare function isWasmBinary(bytes: Uint8Array): boolean;
|
|
3132
|
+
|
|
3133
|
+
/**
|
|
3134
|
+
* `wasi` — the interpreter that stands behind every `.wasm` file in `$PATH`.
|
|
3135
|
+
*
|
|
3136
|
+
* It is invoked two ways, and they are the same code path. A user can run
|
|
3137
|
+
* `wasi build/tool.wasm --flag`, or they can `chmod +x tool.wasm && ./tool.wasm
|
|
3138
|
+
* --flag` and let the kernel dispatch it here the way it dispatches a `#!`
|
|
3139
|
+
* script. The second is the one that matters: it is what makes a compiled
|
|
3140
|
+
* binary indistinguishable from any other program on the system.
|
|
3141
|
+
*/
|
|
3142
|
+
|
|
3143
|
+
declare const wasi: Command;
|
|
3144
|
+
|
|
2908
3145
|
/**
|
|
2909
3146
|
* Starting the guest Worker, in whichever environment the host happens to be.
|
|
2910
3147
|
*
|
|
@@ -3009,4 +3246,4 @@ declare function renderInto(box: Container, element: HTMLElement, options?: {
|
|
|
3009
3246
|
* ```
|
|
3010
3247
|
*/
|
|
3011
3248
|
|
|
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 };
|
|
3249
|
+
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
|
@@ -2905,6 +2905,243 @@ declare class CleanPackageInstaller implements RuntimePackageInstaller {
|
|
|
2905
2905
|
}
|
|
2906
2906
|
declare function extractNpmTarball(volume: RuntimeVolume, compressed: Uint8Array, destination: string): void;
|
|
2907
2907
|
|
|
2908
|
+
/**
|
|
2909
|
+
* Running a `wasm32-wasi` binary as an ordinary container process.
|
|
2910
|
+
*
|
|
2911
|
+
* Everything a guest sees is taken from the `ExecContext` it was dispatched
|
|
2912
|
+
* with — argv, environment, cwd, credentials, the three streams — so a wasm
|
|
2913
|
+
* binary is pipelineable, redirectable and killable exactly like `grep` is.
|
|
2914
|
+
* That is the whole point: `./tool.wasm < input | sort` has to work, or this
|
|
2915
|
+
* is a demo rather than a runtime.
|
|
2916
|
+
*/
|
|
2917
|
+
|
|
2918
|
+
interface RunWasiOptions {
|
|
2919
|
+
/** Guest argv. Defaults to the context's own. */
|
|
2920
|
+
argv?: string[];
|
|
2921
|
+
/** Guest directory name → container path. */
|
|
2922
|
+
preopens?: Record<string, string>;
|
|
2923
|
+
/** Extra imports, for a module linked against more than WASI. */
|
|
2924
|
+
imports?: WebAssembly.Imports;
|
|
2925
|
+
}
|
|
2926
|
+
/** Load, instantiate and run a WebAssembly binary; returns its exit code. */
|
|
2927
|
+
declare function runWasi(ctx: ExecContext, bytes: Uint8Array, options?: RunWasiOptions): Promise<number>;
|
|
2928
|
+
|
|
2929
|
+
/**
|
|
2930
|
+
* A `wasi_snapshot_preview1` host, implemented against this container's kernel.
|
|
2931
|
+
*
|
|
2932
|
+
* The point of this file is that "run a native app" stops being a special
|
|
2933
|
+
* case. A program compiled to `wasm32-wasi` — by clang, Rust, Zig, Go's
|
|
2934
|
+
* `GOOS=wasip1`, TinyGo — asks for files, arguments, environment, clocks and
|
|
2935
|
+
* standard I/O through this one interface. Implement it against the VFS, the
|
|
2936
|
+
* process table and the container's streams, and those programs run beside the
|
|
2937
|
+
* coreutils with the same paths, the same permissions and the same pipes.
|
|
2938
|
+
*
|
|
2939
|
+
* Three constraints shape everything here.
|
|
2940
|
+
*
|
|
2941
|
+
* **Imports must be synchronous.** A WebAssembly import cannot await, but the
|
|
2942
|
+
* kernel's stdin is a promise. So stdin is drained *before* the module starts
|
|
2943
|
+
* (see `run.ts`) and served from a buffer; output streams are already
|
|
2944
|
+
* synchronous. This is the same trade the Python bridge makes, for the same
|
|
2945
|
+
* reason, and it is why an interactive `wasm` REPL reading a live terminal is
|
|
2946
|
+
* out of scope until stack-switching is available here.
|
|
2947
|
+
*
|
|
2948
|
+
* **The VFS has no file descriptors.** It reads and writes whole files. So an
|
|
2949
|
+
* open file is held as a buffer with a cursor, and written back on close, on
|
|
2950
|
+
* sync, and before any path-based call that could otherwise observe a stale
|
|
2951
|
+
* version of the file being written.
|
|
2952
|
+
*
|
|
2953
|
+
* **Capabilities are the VFS's, not a second model.** WASI's rights bitmask is
|
|
2954
|
+
* carried and reported, but enforcement is the kernel's own uid/gid check
|
|
2955
|
+
* running underneath every call. Preopens are enforced, because those *are*
|
|
2956
|
+
* meaningful here: a descriptor cannot escape the directory it was derived
|
|
2957
|
+
* from, so a caller that preopens only `/workspace` gets a program confined to
|
|
2958
|
+
* it.
|
|
2959
|
+
*/
|
|
2960
|
+
|
|
2961
|
+
/** Standard input, already reduced to something readable without waiting. */
|
|
2962
|
+
interface WasiStdin {
|
|
2963
|
+
/** Up to `size` bytes; empty means end-of-file. Never blocks. */
|
|
2964
|
+
read(size: number): Uint8Array;
|
|
2965
|
+
/** Bytes that could be produced right now, for `poll_oneoff`. */
|
|
2966
|
+
readonly available: number;
|
|
2967
|
+
readonly isTTY: boolean;
|
|
2968
|
+
}
|
|
2969
|
+
interface WasiHostOptions {
|
|
2970
|
+
/** Full guest argv, `argv[0]` included. */
|
|
2971
|
+
argv: string[];
|
|
2972
|
+
env: Record<string, string>;
|
|
2973
|
+
vfs: Vfs;
|
|
2974
|
+
cred: Cred;
|
|
2975
|
+
/** Where relative guest paths resolve; published to the guest as `PWD`. */
|
|
2976
|
+
cwd: string;
|
|
2977
|
+
stdin: WasiStdin;
|
|
2978
|
+
stdout: OutputStream;
|
|
2979
|
+
stderr: OutputStream;
|
|
2980
|
+
/**
|
|
2981
|
+
* Guest path → container path. Defaults to the whole filesystem.
|
|
2982
|
+
*
|
|
2983
|
+
* Names are guest-visible *paths*, not labels: wasi-libc matches an open
|
|
2984
|
+
* against the longest preopen prefix, so a preopen called `.` claims every
|
|
2985
|
+
* absolute path as well and quietly turns `/work/out.txt` into
|
|
2986
|
+
* `work/out.txt` under whatever `.` points at. Relative paths need no
|
|
2987
|
+
* preopen of their own — libc joins them to `PWD` before it asks.
|
|
2988
|
+
*/
|
|
2989
|
+
preopens?: Record<string, string>;
|
|
2990
|
+
now?: () => number;
|
|
2991
|
+
/** Monotonic nanosecond source, for `clock_time_get(MONOTONIC)`. */
|
|
2992
|
+
hrtime?: () => bigint;
|
|
2993
|
+
random?: (into: Uint8Array) => void;
|
|
2994
|
+
/** Blocking sleep. Returning early is allowed; the guest re-polls. */
|
|
2995
|
+
sleep?: (ms: number) => void;
|
|
2996
|
+
/** Consulted between sleep slices so a killed process stops waiting. */
|
|
2997
|
+
aborted?: () => boolean;
|
|
2998
|
+
}
|
|
2999
|
+
/** Thrown by `proc_exit` to unwind the guest's stack out to the runner. */
|
|
3000
|
+
declare class WasiExit extends Error {
|
|
3001
|
+
readonly code: number;
|
|
3002
|
+
constructor(code: number);
|
|
3003
|
+
}
|
|
3004
|
+
declare class WasiHost {
|
|
3005
|
+
private memory;
|
|
3006
|
+
private readonly fds;
|
|
3007
|
+
private nextFd;
|
|
3008
|
+
private readonly opts;
|
|
3009
|
+
private readonly startTime;
|
|
3010
|
+
/** Set once `proc_exit` has run, so the runner reports the guest's code. */
|
|
3011
|
+
exitCode: number | null;
|
|
3012
|
+
constructor(options: WasiHostOptions);
|
|
3013
|
+
/** Attach the instance's memory. Called before `_start`. */
|
|
3014
|
+
bind(instance: WebAssembly.Instance): void;
|
|
3015
|
+
/** Flush every buffered write. Called by the runner when the guest ends. */
|
|
3016
|
+
flushAll(): void;
|
|
3017
|
+
/**
|
|
3018
|
+
* `wasi_snapshot_preview1`.
|
|
3019
|
+
*
|
|
3020
|
+
* Every entry returns an errno rather than throwing: a JavaScript exception
|
|
3021
|
+
* crossing back into WebAssembly traps the instance, which turns a missing
|
|
3022
|
+
* file into an unrecoverable crash instead of the `ENOENT` the guest is
|
|
3023
|
+
* written to handle. `guard` is what enforces that.
|
|
3024
|
+
*/
|
|
3025
|
+
get wasiImport(): Record<string, (...args: never[]) => unknown>;
|
|
3026
|
+
/**
|
|
3027
|
+
* `wasi_unstable`, the preview0 name older toolchains still emit.
|
|
3028
|
+
*
|
|
3029
|
+
* Identical but for `fd_seek`, whose `whence` values were reordered before
|
|
3030
|
+
* preview1 was frozen. Aliasing the table without this correction is a
|
|
3031
|
+
* popular bug: every seek in an old binary lands somewhere plausible and
|
|
3032
|
+
* wrong.
|
|
3033
|
+
*/
|
|
3034
|
+
get wasiUnstableImport(): Record<string, (...args: never[]) => unknown>;
|
|
3035
|
+
private get view();
|
|
3036
|
+
private get bytes();
|
|
3037
|
+
private readString;
|
|
3038
|
+
/** The scatter/gather list `fd_read` and `fd_write` are given. */
|
|
3039
|
+
private iovecs;
|
|
3040
|
+
/**
|
|
3041
|
+
* Turn anything thrown inside a syscall into an errno.
|
|
3042
|
+
*
|
|
3043
|
+
* `WasiExit` is re-thrown on purpose: it is the guest unwinding its own
|
|
3044
|
+
* stack, not a failure to be reported through a return value.
|
|
3045
|
+
*/
|
|
3046
|
+
private guard;
|
|
3047
|
+
private get;
|
|
3048
|
+
private dir;
|
|
3049
|
+
private file;
|
|
3050
|
+
/**
|
|
3051
|
+
* Resolve a guest path against a directory descriptor.
|
|
3052
|
+
*
|
|
3053
|
+
* The confinement check is the one place preopens are enforced: a path that
|
|
3054
|
+
* climbs out of the directory the descriptor was derived from is
|
|
3055
|
+
* `ENOTCAPABLE`, which is exactly the error a capability-oriented guest
|
|
3056
|
+
* expects and knows how to report.
|
|
3057
|
+
*/
|
|
3058
|
+
private resolveAt;
|
|
3059
|
+
private allocate;
|
|
3060
|
+
/**
|
|
3061
|
+
* Push a buffered file back to the VFS.
|
|
3062
|
+
*
|
|
3063
|
+
* Called before every path-based call as well as on close, so a guest that
|
|
3064
|
+
* writes a file and then stats or reopens it by name sees what it wrote —
|
|
3065
|
+
* the alternative is a stale read that looks like data loss.
|
|
3066
|
+
*/
|
|
3067
|
+
private writeBack;
|
|
3068
|
+
private syncPaths;
|
|
3069
|
+
private args_get;
|
|
3070
|
+
private args_sizes_get;
|
|
3071
|
+
private get envStrings();
|
|
3072
|
+
private environ_get;
|
|
3073
|
+
private environ_sizes_get;
|
|
3074
|
+
private writeStringVector;
|
|
3075
|
+
private writeVectorSizes;
|
|
3076
|
+
private clock_res_get;
|
|
3077
|
+
private clock_time_get;
|
|
3078
|
+
private clockNow;
|
|
3079
|
+
private random_get;
|
|
3080
|
+
private fd_read;
|
|
3081
|
+
private fd_pread;
|
|
3082
|
+
private fd_write;
|
|
3083
|
+
private fd_pwrite;
|
|
3084
|
+
private fd_seek;
|
|
3085
|
+
private fd_tell;
|
|
3086
|
+
private fd_close;
|
|
3087
|
+
private fd_sync;
|
|
3088
|
+
private fd_renumber;
|
|
3089
|
+
private fd_allocate;
|
|
3090
|
+
private fd_filestat_set_size;
|
|
3091
|
+
private fd_fdstat_get;
|
|
3092
|
+
private fd_fdstat_set_flags;
|
|
3093
|
+
private fd_filestat_get;
|
|
3094
|
+
private fd_filestat_set_times;
|
|
3095
|
+
private path_filestat_get;
|
|
3096
|
+
private path_filestat_set_times;
|
|
3097
|
+
private setTimes;
|
|
3098
|
+
private writeFilestat;
|
|
3099
|
+
private fd_prestat_get;
|
|
3100
|
+
private fd_prestat_dir_name;
|
|
3101
|
+
private path_open;
|
|
3102
|
+
private fd_readdir;
|
|
3103
|
+
private path_create_directory;
|
|
3104
|
+
private path_remove_directory;
|
|
3105
|
+
private path_unlink_file;
|
|
3106
|
+
private path_rename;
|
|
3107
|
+
private path_symlink;
|
|
3108
|
+
private path_link;
|
|
3109
|
+
private path_readlink;
|
|
3110
|
+
/**
|
|
3111
|
+
* `poll_oneoff`, which is how a WASI guest sleeps and how it waits on I/O.
|
|
3112
|
+
*
|
|
3113
|
+
* Files and the standard streams are always ready here — nothing in this
|
|
3114
|
+
* container can leave a read pending, since stdin was drained before the
|
|
3115
|
+
* guest started. That leaves the clock, which is the case that matters:
|
|
3116
|
+
* `sleep()` compiles to a lone clock subscription, and it is honoured by
|
|
3117
|
+
* actually waiting, in slices, so that killing the process interrupts it.
|
|
3118
|
+
*/
|
|
3119
|
+
private poll_oneoff;
|
|
3120
|
+
private bytesLeft;
|
|
3121
|
+
/** Wait in slices so that a `SIGKILL` does not have to outlast the sleep. */
|
|
3122
|
+
private sleepInterruptibly;
|
|
3123
|
+
}
|
|
3124
|
+
/** An errno on its way back to the guest, rather than a JavaScript failure. */
|
|
3125
|
+
declare class WasiError extends Error {
|
|
3126
|
+
readonly errno: number;
|
|
3127
|
+
constructor(errno: number);
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
/** Whether `bytes` begins with the WebAssembly magic number. */
|
|
3131
|
+
declare function isWasmBinary(bytes: Uint8Array): boolean;
|
|
3132
|
+
|
|
3133
|
+
/**
|
|
3134
|
+
* `wasi` — the interpreter that stands behind every `.wasm` file in `$PATH`.
|
|
3135
|
+
*
|
|
3136
|
+
* It is invoked two ways, and they are the same code path. A user can run
|
|
3137
|
+
* `wasi build/tool.wasm --flag`, or they can `chmod +x tool.wasm && ./tool.wasm
|
|
3138
|
+
* --flag` and let the kernel dispatch it here the way it dispatches a `#!`
|
|
3139
|
+
* script. The second is the one that matters: it is what makes a compiled
|
|
3140
|
+
* binary indistinguishable from any other program on the system.
|
|
3141
|
+
*/
|
|
3142
|
+
|
|
3143
|
+
declare const wasi: Command;
|
|
3144
|
+
|
|
2908
3145
|
/**
|
|
2909
3146
|
* Starting the guest Worker, in whichever environment the host happens to be.
|
|
2910
3147
|
*
|
|
@@ -3009,4 +3246,4 @@ declare function renderInto(box: Container, element: HTMLElement, options?: {
|
|
|
3009
3246
|
* ```
|
|
3010
3247
|
*/
|
|
3011
3248
|
|
|
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 };
|
|
3249
|
+
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 };
|