codecrucible-synth
Version:
Production-Ready AI Development Platform with Multi-Voice Synthesis, Smithery MCP Integration, Enterprise Security, and Zero-Timeout Reliability
221 lines • 6.6 kB
TypeScript
/**
* Switchable Execution Backend System
*
* Provides configurable code execution with support for:
* - Docker containers
* - E2B cloud sandboxes
* - E2B self-hosted sandboxes
* - Local process execution (with safeguards)
*/
import { ServiceResponse } from '../error-handling/structured-error-system.js';
export interface ExecutionResult {
stdout: string;
stderr: string;
exitCode: number;
success: boolean;
duration: number;
backend: string;
metadata?: {
containerId?: string;
sandboxId?: string;
vmId?: string;
memoryUsed?: number;
cpuTime?: number;
vcpuCount?: number;
memSizeMib?: number;
rootless?: boolean;
networkMode?: string;
};
}
export interface ExecutionOptions {
timeout?: number;
workingDirectory?: string;
environment?: Record<string, string>;
stdin?: string;
captureOutput?: boolean;
maxOutputSize?: number;
}
export interface BackendConfig {
type: 'docker' | 'e2b' | 'local_e2b' | 'local_process' | 'firecracker' | 'podman';
dockerImage?: string;
e2bApiKey?: string;
e2bEndpoint?: string;
e2bTemplate?: string;
localSafeguards?: boolean;
allowedCommands?: string[];
maxConcurrent?: number;
firecrackerKernelPath?: string;
firecrackerRootfsPath?: string;
firecrackerVcpuCount?: number;
firecrackerMemSizeMib?: number;
podmanRootless?: boolean;
podmanImage?: string;
podmanNetworkMode?: string;
}
/**
* Abstract base class for execution backends
*/
export declare abstract class ExecutionBackend {
protected config: BackendConfig;
protected activeExecutions: number;
private executionLock;
constructor(config: BackendConfig);
abstract execute(command: string, options?: ExecutionOptions): Promise<ServiceResponse<ExecutionResult>>;
abstract cleanup(): Promise<void>;
abstract getStatus(): {
type: string;
active: number;
available: boolean;
config: any;
};
protected canExecute(): boolean;
protected acquireExecutionSlot(): Promise<boolean>;
protected releaseExecutionSlot(): void;
protected validateWorkingDirectory(path: string): {
safe: boolean;
reason?: string;
};
}
/**
* Docker execution backend
*/
export declare class DockerBackend extends ExecutionBackend {
private containerPrefix;
private activeContainers;
constructor(config: BackendConfig);
execute(command: string, options?: ExecutionOptions): Promise<ServiceResponse<ExecutionResult>>;
cleanup(): Promise<void>;
getStatus(): {
type: string;
active: number;
available: boolean;
config: {
image: string | undefined;
activeContainers: number;
};
};
}
/**
* E2B Cloud execution backend
*/
export declare class E2BBackend extends ExecutionBackend {
private sandboxes;
constructor(config: BackendConfig);
execute(command: string, options?: ExecutionOptions): Promise<ServiceResponse<ExecutionResult>>;
cleanup(): Promise<void>;
getStatus(): {
type: string;
active: number;
available: boolean;
config: {
template: string | undefined;
endpoint: string;
activeSandboxes: number;
};
};
}
/**
* Local E2B execution backend (self-hosted)
*/
export declare class LocalE2BBackend extends E2BBackend {
constructor(config: BackendConfig);
execute(command: string, options?: ExecutionOptions): Promise<ServiceResponse<ExecutionResult>>;
getStatus(): {
type: string;
active: number;
available: boolean;
config: {
template: string | undefined;
endpoint: string;
activeSandboxes: number;
};
};
}
/**
* Firecracker execution backend for microVM isolation
*/
export declare class FirecrackerBackend extends ExecutionBackend {
private activeVMs;
private vmPrefix;
constructor(config: BackendConfig);
execute(command: string, options?: ExecutionOptions): Promise<ServiceResponse<ExecutionResult>>;
private executeInVM;
cleanup(): Promise<void>;
getStatus(): {
type: string;
active: number;
available: boolean;
config: {
kernelPath: string | undefined;
rootfsPath: string | undefined;
vcpuCount: number | undefined;
memSizeMib: number | undefined;
activeVMs: number;
};
};
}
/**
* Podman execution backend for rootless containers
*/
export declare class PodmanBackend extends ExecutionBackend {
private containerPrefix;
private activeContainers;
constructor(config: BackendConfig);
execute(command: string, options?: ExecutionOptions): Promise<ServiceResponse<ExecutionResult>>;
private filterEnvironmentVariables;
cleanup(): Promise<void>;
getStatus(): {
type: string;
active: number;
available: boolean;
config: {
image: string | undefined;
rootless: boolean | undefined;
networkMode: string | undefined;
activeContainers: number;
};
};
}
/**
* Local process execution backend (with safeguards)
*/
export declare class LocalProcessBackend extends ExecutionBackend {
private readonly dangerousCommands;
constructor(config: BackendConfig);
execute(command: string, options?: ExecutionOptions): Promise<ServiceResponse<ExecutionResult>>;
private checkCommandSafety;
cleanup(): Promise<void>;
getStatus(): {
type: string;
active: number;
available: boolean;
config: {
safeguards: boolean | undefined;
allowedCommands: string[] | undefined;
};
};
}
/**
* Execution backend factory
*/
export declare class ExecutionBackendFactory {
static create(config: BackendConfig): ExecutionBackend;
static detectAvailable(): Promise<string[]>;
}
/**
* Multi-backend execution manager
*/
export declare class ExecutionManager {
private backends;
private defaultBackend;
constructor(configs: BackendConfig[], defaultBackend?: string);
execute(command: string, options?: ExecutionOptions & {
backend?: string;
}): Promise<ServiceResponse<ExecutionResult>>;
cleanup(): Promise<void>;
getStatus(): Record<string, any>;
setDefaultBackend(type: string): void;
getAvailableBackends(): string[];
}
export default ExecutionManager;
//# sourceMappingURL=execution-backend.d.ts.map