/** * Process sandbox helpers: timeout, byte caps, fd budget, optional * cgroup-v2. The sandbox returns an `applyTo` callable that wraps a * spawned child process with kill-on-overflow guards. */ import { promises as fs } from "node:fs"; import type { ChildProcess } from "node:child_process"; import type { SandboxProfile } from "./allowlist.js"; export interface SandboxLimits { timeoutMs: number; maxStdoutBytes: number; maxStderrBytes: number; fdBudget: number; /** cgroup limits applied if cgroup-v2 is detected and writable. */ cgroup?: { memoryMaxBytes: number; cpuMaxQuota: number; }; } export declare const SANDBOX_PROFILES: Record; export interface SandboxStatus { profile: SandboxProfile; timeoutMs: number; maxStdoutBytes: number; maxStderrBytes: number; fdBudget: number; cgroupActive: boolean; cgroupLimits?: { memoryMaxBytes: number; cpuMaxQuota: number; }; } export interface CgroupProbeResult { active: boolean; reason?: string; } /** * Detect whether cgroup-v2 is mounted writable for non-root sub-folders. * Pure read-only access — never writes here. Caller decides whether to * actually create a cgroup. */ export declare function probeCgroupV2(cgroupRoot?: string, fsApi?: { access: typeof fs.access; }): Promise; /** * Resolve a profile name to concrete limits. */ export declare function resolveLimits(profile: SandboxProfile): SandboxLimits; export interface SandboxAttachOptions { child: ChildProcess; limits: SandboxLimits; /** Called with the bytes captured so far on stdout. */ onStdoutChunk?: (totalBytes: number) => void; onStderrChunk?: (totalBytes: number) => void; } export interface SandboxAttachResult { stdoutPromise: Promise; stderrPromise: Promise; /** Resolves when the process has exited cleanly within limits. */ exitPromise: Promise<{ exitCode: number; signal: NodeJS.Signals | null; }>; /** Cancel the timeout / abort handlers. Always call in a finally. */ cleanup: () => void; } /** * Attach overflow + timeout guards to an already-spawned child. The * child is killed (SIGKILL after SIGTERM grace) if any limit is hit. */ export declare function attachSandbox(opts: SandboxAttachOptions): SandboxAttachResult; //# sourceMappingURL=sandbox.d.ts.map