/** * postgres-mcp - Code Mode Sandbox * * Sandboxed execution environment using Node.js vm module. * Provides code isolation with memory/time limits for LLM-generated code. * * Note: This uses Node.js vm module which provides script isolation but not * true V8 isolate separation. For production environments with untrusted code, * consider using isolated-vm or running in a separate process/container. */ import { type SandboxOptions, type PoolOptions, type SandboxResult } from "./types.js"; /** * A sandboxed execution context using Node.js vm module */ export declare class CodeModeSandbox { private context; private readonly options; private disposed; private readonly logBuffer; /** * LRU cache of compiled vm.Script instances keyed by wrapped code string. * Avoids the expensive vm.Script compilation on repeated executions of * the same code (common in benchmarks and agent retry loops). */ private readonly scriptCache; private constructor(); /** * Create a new sandbox instance */ static create(options?: SandboxOptions): CodeModeSandbox; /** * Execute code in the sandbox * @param code - TypeScript/JavaScript code to execute * @param apiBindings - Object with pg.* API methods to expose * @param timeoutMs - Optional execution timeout in milliseconds */ execute(code: string, apiBindings: Record, timeoutMs?: number): Promise; /** * Retrieve a compiled vm.Script from the LRU cache, or compile and cache it. * Evicts the oldest entry when the cache exceeds SCRIPT_CACHE_MAX. */ private getOrCompileScript; /** * Calculate execution metrics. * Uses RSS delta (process.memoryUsage.rss()) instead of heapUsed * for significantly lower syscall overhead on Windows. */ private calculateMetrics; /** * Get console output from the sandbox */ getConsoleOutput(): string[]; /** * Clear console output buffer */ clearConsoleOutput(): void; /** * Check if sandbox is healthy */ isHealthy(): boolean; /** * Dispose of the sandbox and release resources */ dispose(): void; } /** * Pool of sandbox instances for reuse */ export declare class SandboxPool { private readonly options; private readonly sandboxOptions; private readonly available; private readonly inUse; private disposed; private cleanupInterval; constructor(poolOptions?: PoolOptions, sandboxOptions?: SandboxOptions); /** * Initialize the pool with minimum instances */ initialize(): void; /** * Acquire a sandbox from the pool */ acquire(): CodeModeSandbox; /** * Release a sandbox back to the pool */ release(sandbox: CodeModeSandbox): void; /** * Execute code using a pooled sandbox */ execute(code: string, apiBindings: Record, timeoutMs?: number): Promise; /** * Clean up excess idle sandboxes */ private cleanup; /** * Get pool statistics */ getStats(): { available: number; inUse: number; max: number; }; /** * Dispose of all sandboxes in the pool */ dispose(): void; } //# sourceMappingURL=sandbox.d.ts.map