UNPKG

signalk-mcp-server

Version:
87 lines 2.45 kB
/** * Result of code execution in V8 isolate */ export interface ExecutionResult { success: boolean; result?: any; error?: string; logs: string[]; executionTime: number; } /** * Resource limits for isolate execution */ export interface SandboxLimits { memoryLimitMB?: number; timeoutMs?: number; } /** * Bindings that can be injected into isolate context * These provide controlled access to external capabilities */ export interface SandboxBindings { [key: string]: any; } /** * V8 Isolate-based code execution sandbox * * Uses isolated-vm to execute agent-written code in a secure V8 isolate. * Provides: * - Memory isolation (default 128MB limit) * - Execution timeout (default 30s) * - No network access from sandbox * - No filesystem access (except via bindings) * - Console output capture * * Based on Cloudflare's Code Mode architecture: * - Fresh isolate per execution (milliseconds startup) * - Binding-based access to external systems (RPC-style) * - No credentials exposed to sandbox code * * @example * const sandbox = new IsolateSandbox(); * const result = await sandbox.execute(` * console.log('Hello from isolate'); * return 42; * `); * console.log(result.logs); // ['Hello from isolate'] * console.log(result.result); // 42 */ export declare class IsolateSandbox { private limits; constructor(limits?: SandboxLimits); /** * Execute code in a fresh V8 isolate * * @param code - JavaScript/TypeScript code to execute * @param bindings - Optional bindings to inject into isolate context * @returns ExecutionResult with output, logs, and timing * * @example * // Simple execution * const result = await sandbox.execute('2 + 2'); * console.log(result.result); // 4 * * // With bindings * const result = await sandbox.execute( * 'await signalk.getVesselState()', * { signalk: new SignalKBinding() } * ); */ execute(code: string, bindings?: SandboxBindings): Promise<ExecutionResult>; /** * Inject a binding into the isolate context * Bindings are objects with methods that can be called from agent code * * @private */ private injectBinding; /** * Extract result from isolate * Handles primitives, objects, and arrays * * @private */ private extractResult; } //# sourceMappingURL=isolate-sandbox.d.ts.map