/** * PolyglotExecutor — spawn user code in a detected runtime. * * Approach ported from context-mode `PolyglotExecutor` (rewritten fresh in TS; * no source copied). One temp script is written per language, the resolved * runtime is spawned with it, stdout/stderr are streamed to a byte cap, and a * timeout kills the whole process group on expiry. * * SECURITY / TRUST MODEL (read before extending): * massa-th0th is a LOCAL-DEV tool. `execute` / `execute_file` run * USER-SUPPLIED code ON THE HOST — there is no OS-level sandbox (no * seccomp, no namespaces, no cgroups). Containment is BEST-EFFORT: * - default `cwd` is the caller's project root (so relative paths resolve * naturally), but the code can still read/write anywhere the host user * can. Document this; do not imply isolation. * - timeouts are enforced (default 30s, cap 300s) and kill the process * GROUP so orphaned children cannot outlive a killed parent. * - a runtime-injection env denylist strips known code-injection vectors * (NODE_OPTIONS, LD_PRELOAD, BASH_ENV, …) from the inherited env. * - `execute_file` additionally enforces a project-boundary check plus a * deny-glob guard so it won't read paths outside cwd or sensitive * patterns by default. * For multi-tenant or untrusted input, this executor is NOT sufficient — * wrap it in a real container/VM. */ import { type RuntimeMap, type Language, type DetectDeps } from "./runtime.js"; /** Result of a single execution. */ export interface ExecResult { stdout: string; stderr: string; exitCode: number | null; /** True when the process was killed because `timeout` elapsed. */ timedOut: boolean; /** True when the process was detached (background mode) at timeout. */ backgrounded?: boolean; /** Command + runtime that were actually invoked (for diagnostics). */ command?: string; /** Effective cwd the script ran in. */ cwd?: string; } export interface ExecuteOptions { language: Language; code: string; /** Max runtime in ms. Default 30_000; hard cap MAX_TIMEOUT_MS. */ timeout?: number; /** Detach instead of kill on timeout. Process group is tracked + killable. */ background?: boolean; /** Override cwd (default = projectRoot / process.cwd()). */ cwd?: string; } export interface ExecuteFileOptions extends ExecuteOptions { /** Project-relative (or absolute) path of the file to load into a var. */ path: string; } /** * Default + hard-cap timeout. The default (30s) is conservative on purpose — * most sandbox probes (print, parse, count) finish in <1s. The hard cap * (300s) bounds runaway builds/installs invoked from user code. */ export declare const DEFAULT_TIMEOUT_MS = 30000; export declare const MAX_TIMEOUT_MS = 300000; /** Combined stdout+stderr byte cap. Prevents `yes`/`/dev/urandom` OOMs. */ export declare const DEFAULT_HARD_CAP_BYTES: number; export declare class PolyglotExecutor { #private; constructor(opts?: { hardCapBytes?: number; projectRoot?: string | (() => string); runtimes?: RuntimeMap; deps?: DetectDeps; }); get runtimes(): RuntimeMap; get projectRoot(): string; /** * Kill all backgrounded processes (SIGTERM the group). Call on shutdown to * prevent zombies / port conflicts. */ cleanupBackgrounded(): void; /** * Run `code` in the chosen language's detected runtime. * * The script FILE lives in a sandbox tmpDir; the process CWD is the project * root (or `cwd` override) so repo-relative paths resolve naturally. */ execute(opts: ExecuteOptions): Promise; /** * Read `path` into a sandboxed FILE_CONTENT var, then run `code` over it. * Enforces project-boundary containment + deny-glob before execution so a * stray path can't exfiltrate secrets by default. * * SYMLINK DEFENSE: the boundary + deny-glob checks run against the REALPATH * of both the target file and the project root. A symlink inside the project * root pointing to `/etc/passwd` or a non-deny-glob secrets file would * otherwise pass both checks (its link path is under root and may not match * a deny pattern), then `readFileSync` follows the symlink out of the * project. Resolving symlinks first closes this bypass. If the target does * not exist yet (realpathSync throws ENOENT), we fall back to the lexical * absolute path so a missing-file error surfaces from the read, not a * spurious "blocked" message. */ executeFile(opts: ExecuteFileOptions): Promise; } //# sourceMappingURL=executor.d.ts.map