import type { NodeModulesMountConfig } from "./host-dir-mount.js"; export declare const AF_INET = 2; export declare const AF_UNIX = 1; export declare const SOCK_STREAM = 1; export declare const SOCK_DGRAM = 2; export declare const SIGTERM = 15; export type StdioChannel = "stdout" | "stderr"; export type TimingMitigation = "off" | "freeze"; export type PermissionMode = "allow" | "deny"; export type PermissionDecision = PermissionMode; export interface VirtualDirEntry { name: string; isDirectory: boolean; isSymbolicLink?: boolean; } export interface VirtualStat { mode: number; size: number; sizeExact?: bigint; blocks: number; dev: number; rdev: number; isDirectory: boolean; isSymbolicLink: boolean; atimeMs: number; mtimeMs: number; ctimeMs: number; birthtimeMs: number; ino: number; inoExact?: bigint; nlink: number; nlinkExact?: bigint; uid: number; gid: number; } export interface VirtualFileSystem { readFile(path: string): Promise; readTextFile(path: string): Promise; readDir(path: string): Promise; readDirWithTypes(path: string): Promise; writeFile(path: string, content: string | Uint8Array): Promise; createDir(path: string): Promise; mkdir(path: string, options?: { recursive?: boolean; }): Promise; exists(path: string): Promise; stat(path: string): Promise; removeFile(path: string): Promise; removeDir(path: string): Promise; rename(oldPath: string, newPath: string): Promise; realpath(path: string): Promise; symlink(target: string, linkPath: string): Promise; readlink(path: string): Promise; lstat(path: string): Promise; link(oldPath: string, newPath: string): Promise; chmod(path: string, mode: number): Promise; chown(path: string, uid: number, gid: number, options?: { followSymlinks?: boolean; }): Promise; utimes(path: string, atime: number, mtime: number): Promise; truncate(path: string, length: number): Promise; pread(path: string, offset: number, length: number): Promise; pwrite(path: string, offset: number, data: Uint8Array): Promise; } export interface NetworkAccessRequest { url?: string; host?: string; port?: number; protocol?: string; } export interface FsPermissionRule { mode: PermissionMode; operations?: string[]; paths?: string[]; } export interface PatternPermissionRule { mode: PermissionMode; operations?: string[]; patterns?: string[]; } export interface RulePermissions { default?: PermissionMode; rules: TRule[]; } export type FsPermissions = PermissionMode | RulePermissions; export type NetworkPermissions = PermissionMode | RulePermissions; export type ChildProcessPermissions = PermissionMode | RulePermissions; export type ProcessPermissions = PermissionMode | RulePermissions; export type EnvPermissions = PermissionMode | RulePermissions; export type BindingPermissions = PermissionMode | RulePermissions; export interface ProcessInfo { pid: number; ppid: number; pgid: number; sid: number; driver: string; command: string; args: string[]; cwd: string; status: "running" | "exited"; exitCode: number | null; startTime: number; exitTime: number | null; } export interface ManagedProcess { pid: number; writeStdin(data: Uint8Array | string): Promise; closeStdin(): Promise; kill(signal?: number): void; wait(): Promise; readonly exitCode: number | null; } export interface ShellHandle { pid: number; write(data: Uint8Array | string): Promise; /** Ordered PTY output containing stdout and stderr exactly once. */ onData: ((data: Uint8Array) => void) | null; resize(cols: number, rows: number): void; kill(signal?: number): void; wait(): Promise; } export interface OpenShellOptions { command?: string; args?: string[]; env?: Record; cwd?: string; cols?: number; rows?: number; /** Optional stderr-only diagnostic tap; do not render it alongside `onData`. */ onStderr?: (data: Uint8Array) => void; } export interface ConnectTerminalOptions extends OpenShellOptions { onData?: (data: Uint8Array) => void; } export interface ExecOptions { env?: Record; cwd?: string; stdin?: string | Uint8Array; timeout?: number; onStdout?: (data: Uint8Array) => void; onStderr?: (data: Uint8Array) => void; captureStdio?: boolean; filePath?: string; cpuTimeLimitMs?: number; timingMitigation?: TimingMitigation; } export interface ExecResult { exitCode: number; stdout: string; stderr: string; } export interface RunResult { value?: T; code: number; errorMessage?: string; } export interface KernelSpawnOptions extends ExecOptions { stdio?: "pipe" | "inherit"; stdinFd?: number; stdoutFd?: number; stderrFd?: number; streamStdin?: boolean; } export type KernelExecOptions = ExecOptions; export type KernelExecResult = ExecResult; export type StatInfo = VirtualStat; export type DirEntry = VirtualDirEntry; export type StdioEvent = { channel: StdioChannel; message: string; }; export type StdioHook = (event: StdioEvent) => void; export interface Permissions { fs?: FsPermissions; network?: NetworkPermissions; childProcess?: ChildProcessPermissions; process?: ProcessPermissions; env?: EnvPermissions; binding?: BindingPermissions; } export interface ResourceBudgets { maxOutputBytes?: number; maxBridgeCalls?: number; maxTimers?: number; maxChildProcesses?: number; maxHandles?: number; } export interface ProcessConfig { cwd?: string; env?: Record; argv?: string[]; stdinIsTTY?: boolean; stdoutIsTTY?: boolean; stderrIsTTY?: boolean; } export interface OSConfig { homedir?: string; tmpdir?: string; } export interface CommandExecutor { spawn(command: string, args: string[], options?: KernelSpawnOptions): ManagedProcess; } export interface NetworkAdapter { fetch(url: string, options?: { method?: string; headers?: Record; body?: unknown; }): Promise<{ ok: boolean; status: number; statusText: string; headers: Record; body: string; url: string; redirected: boolean; }>; dnsLookup(hostname: string): Promise<{ address?: string; family?: number; error?: string; code?: string; }>; httpRequest(url: string, options?: { method?: string; headers?: Record; body?: unknown; }): Promise<{ status: number; statusText: string; headers: Record; body: string; url: string; }>; } export interface SystemDriver { filesystem?: VirtualFileSystem; network?: NetworkAdapter; commandExecutor?: CommandExecutor; permissions?: Permissions; mounts: readonly NodeModulesMountConfig[]; runtime: { process: ProcessConfig; os: OSConfig; }; } export interface RuntimeDriverOptions { system: SystemDriver; runtime: { process: ProcessConfig; os: OSConfig; }; memoryLimit?: number; cpuTimeLimitMs?: number; timingMitigation?: TimingMitigation; onStdio?: StdioHook; payloadLimits?: { base64TransferBytes?: number; jsonPayloadBytes?: number; }; resourceBudgets?: ResourceBudgets; } export interface NodeRuntimeDriver { exec(code: string, options?: ExecOptions): Promise; run(code: string, filePath?: string): Promise>; dispose(): void; terminate?(): Promise; readonly network?: Pick; } export interface NodeRuntimeDriverFactory { createRuntimeDriver(options: RuntimeDriverOptions): NodeRuntimeDriver; } export interface KernelInterface { vfs: VirtualFileSystem; } export interface KernelRecursiveDirEntry { name: string; path: string; isDirectory: boolean; isSymbolicLink: boolean; size: number; } export interface Kernel extends KernelInterface { mount(driver: KernelRuntimeDriver): Promise; dispose(): Promise; exec(command: string, options?: KernelExecOptions): Promise; spawn(command: string, args: string[], options?: KernelSpawnOptions): ManagedProcess; openShell(options?: OpenShellOptions): ShellHandle; connectTerminal(options?: ConnectTerminalOptions): Promise; mountFs(path: string, fs: VirtualFileSystem, options?: { readOnly?: boolean; }): void | Promise; unmountFs(path: string): void | Promise; readFile(path: string): Promise; writeFile(path: string, content: string | Uint8Array): Promise; mkdir(path: string): Promise; readdir(path: string): Promise; readdirRecursive(path: string, options?: { maxDepth?: number; }): Promise; stat(path: string): Promise; exists(path: string): Promise; removeFile(path: string): Promise; removeDir(path: string): Promise; removePath(path: string, options?: { recursive?: boolean; }): Promise; rename(oldPath: string, newPath: string): Promise; movePath(oldPath: string, newPath: string): Promise; readonly commands: ReadonlyMap; readonly processes: ReadonlyMap; readonly env: Record; readonly cwd: string; readonly socketTable: { hasHostNetworkAdapter(): boolean; findListener(_request: unknown): unknown | null; findBoundUdp(_request: unknown): unknown | null; }; readonly processTable: { getSignalState(_pid: number): { handlers: Map; }; }; readonly timerTable: Record; readonly zombieTimerCount: number; } export interface BindingTree { [key: string]: BindingFunction | BindingTree; } export type BindingFunction = (...args: unknown[]) => unknown; export interface NodeDriverOptions { filesystem?: VirtualFileSystem; networkAdapter?: NetworkAdapter; commandExecutor?: CommandExecutor; permissions?: Permissions; mounts?: readonly NodeModulesMountConfig[]; processConfig?: ProcessConfig; osConfig?: OSConfig; } export interface DefaultNetworkAdapterOptions { loopbackExemptPorts?: number[]; } export interface NodeRuntimeOptions { systemDriver?: SystemDriver; runtimeDriverFactory?: NodeRuntimeDriverFactory; permissions?: Partial; memoryLimit?: number; bindings?: BindingTree; loopbackExemptPorts?: number[]; } export type NodeRuntimeDriverFactoryOptions = Record; export type NodeExecutionDriverOptions = RuntimeDriverOptions; export interface KernelRuntimeDriver { readonly kind: "node" | "wasmvm"; readonly name: string; readonly commands: string[]; readonly commandDirs?: string[]; init?(kernel: KernelInterface): Promise | void; tryResolve?(command: string): boolean; getGuestCommandPaths?(startIndex: number): ReadonlyMap; recordModuleExecution?(command: string): void; } export type DriverProcess = ManagedProcess; export type ProcessContext = Record; export declare class KernelError extends Error { readonly code: string; constructor(code: string, message: string); } export declare class NodeFileSystem implements VirtualFileSystem { readonly rootPath: string; constructor(options: { root: string; }); private normalizeTarget; private toStat; readFile(targetPath: string): Promise; readTextFile(targetPath: string): Promise; readDir(targetPath: string): Promise; readDirWithTypes(targetPath: string): Promise; writeFile(targetPath: string, content: string | Uint8Array): Promise; createDir(targetPath: string): Promise; mkdir(targetPath: string, options?: { recursive?: boolean; }): Promise; exists(targetPath: string): Promise; stat(targetPath: string): Promise; removeFile(targetPath: string): Promise; removeDir(targetPath: string): Promise; rename(oldPath: string, newPath: string): Promise; realpath(targetPath: string): Promise; symlink(target: string, linkPath: string): Promise; readlink(targetPath: string): Promise; lstat(targetPath: string): Promise; link(oldPath: string, newPath: string): Promise; chmod(targetPath: string, mode: number): Promise; chown(targetPath: string, uid: number, gid: number): Promise; utimes(targetPath: string, atime: number, mtime: number): Promise; truncate(targetPath: string, length: number): Promise; pread(targetPath: string, offset: number, length: number): Promise; pwrite(targetPath: string, offset: number, data: Uint8Array): Promise; } export declare const allowAllFs: FsPermissions; export declare const allowAllNetwork: NetworkPermissions; export declare const allowAllChildProcess: ChildProcessPermissions; export declare const allowAllProcess: ProcessPermissions; export declare const allowAllEnv: EnvPermissions; export declare const allowAll: Permissions; export declare function filterEnv(env: Record | undefined, permissions?: Permissions): Record; export declare function createProcessScopedFileSystem(filesystem: VirtualFileSystem): VirtualFileSystem; export declare function exists(filesystem: VirtualFileSystem, targetPath: string): Promise; export declare function stat(filesystem: VirtualFileSystem, targetPath: string): Promise; export declare function rename(filesystem: VirtualFileSystem, oldPath: string, newPath: string): Promise; export declare function readDirWithTypes(filesystem: VirtualFileSystem, targetPath: string): Promise; export declare function mkdir(filesystem: VirtualFileSystem, targetPath: string, options?: { recursive?: boolean; }): Promise; export declare function createNodeHostCommandExecutor(): CommandExecutor; export declare function createKernelCommandExecutor(kernel: Kernel): CommandExecutor; export declare function createKernelVfsAdapter(kernelVfs: VirtualFileSystem): VirtualFileSystem; export declare function createHostFallbackVfs(base: VirtualFileSystem): VirtualFileSystem; export declare function isPrivateIp(host: string): boolean; export declare function createNodeHostNetworkAdapter(): NetworkAdapter; export declare function createDefaultNetworkAdapter(): NetworkAdapter; export declare function createNodeDriver(options?: NodeDriverOptions): SystemDriver; export declare class NodeExecutionDriver implements NodeRuntimeDriver { private readonly options; readonly network?: Pick; constructor(options: RuntimeDriverOptions); exec(): Promise; run(): Promise>; dispose(): void; terminate(): Promise; } export declare class NodeRuntime extends NodeExecutionDriver { } export declare function createNodeRuntimeDriverFactory(): NodeRuntimeDriverFactory; export declare const WASMVM_COMMANDS: readonly string[]; export type PermissionTier = "full" | "read-write" | "read-only" | "isolated"; export declare const DEFAULT_FIRST_PARTY_TIERS: Readonly>; export interface WasmVmRuntimeOptions { wasmBinaryPath?: string; commandDirs?: string[]; permissions?: Record; } export declare function createWasmVmRuntime(options?: WasmVmRuntimeOptions): KernelRuntimeDriver; export declare function createNodeRuntime(): KernelRuntimeDriver; export declare function createKernel(options: { filesystem: VirtualFileSystem; permissions?: Permissions; env?: Record; cwd?: string; maxProcesses?: number; hostNetworkAdapter?: unknown; loopbackExemptPorts?: number[]; logger?: unknown; mounts?: Array<{ path: string; fs: VirtualFileSystem; readOnly?: boolean; }>; syncFilesystemOnDispose?: boolean; maxFilesystemBytes?: number; }): Kernel;