import { ICBLogger } from '../logger/cb-logger'; import { HandlerPayload } from '../types/common'; /** * Result of sandbox execution */ export interface ExecutionResult { /** Whether the execution was successful */ success: boolean; /** HTTP status code (200 for success, error code for failures) */ statusCode?: number; /** Error message if execution failed */ error?: string; /** Stack trace if execution failed */ stack?: string | undefined; } /** * Sandbox environment configuration */ export interface SandboxEnvironment { /** Controlled console object */ console: any; /** Read-only payload (event + iparams) passed to handler(payload) */ payload: HandlerPayload; /** Safe async primitives */ setTimeout: typeof setTimeout; clearTimeout: typeof clearTimeout; setImmediate: typeof setImmediate; clearImmediate: typeof clearImmediate; /** CommonJS emulation */ module: { exports: any; }; exports: any; /** Controlled module access */ require: (moduleName: string) => any; /** Limited process access */ process: { cwd: () => string; env: Record; nextTick: typeof process.nextTick; }; /** Prevented escape hatches */ global?: undefined; Buffer?: undefined; __dirname?: undefined; __filename?: undefined; } /** * Interface for sandbox wrapper implementations * This defines the contract that both public and private sandbox implementations must follow */ export interface ISandboxWrapper { /** * Creates a safe require function that uses isolated node_modules * @param projectPath - Path to the user project * @returns A safe require function */ createSafeRequire(projectPath: string): (moduleName: string) => any; /** * Creates a secure sandbox environment for code execution * @param projectPath - Path to the user project * @param payload - Handler payload (event + iparams) to expose to user code as handler(payload) * @param sessionLogger - Logger instance for this server session * @returns The sandbox environment object; handlers are invoked with payload */ createSandbox(projectPath: string, payload: HandlerPayload, sessionLogger: ICBLogger): SandboxEnvironment; /** * Executes user-provided code in a secure sandbox environment * @param userCodePath - Path to the directory containing user code * @param payload - Handler payload (event + iparams) to pass to the user handler * @param sessionLogger - The logger instance for this server session * @returns {Promise} Execution result with success status and data/error */ execute(userCodePath: string, payload: HandlerPayload, sessionLogger: ICBLogger): Promise; }