/**
 * Docker Sandbox Manager
 *
 * Manages per-session Docker container isolation.
 * Provides secure execution environment for tools and commands.
 */
import { EventEmitter } from 'events';
import type { DockerSandboxConfig, SessionContainer, ContainerStatus, ExecutionOptions, ExecutionResult, NetworkPolicy, ContainerMetrics } from './types.js';
/**
 * Docker client interface
 * Can be implemented with dockerode or other Docker clients
 */
export interface IDockerClient {
    /** Check if Docker is available */
    isAvailable(): Promise<boolean>;
    /** Create container */
    createContainer(config: DockerContainerConfig): Promise<string>;
    /** Start container */
    startContainer(containerId: string): Promise<void>;
    /** Stop container */
    stopContainer(containerId: string, timeout?: number): Promise<void>;
    /** Remove container */
    removeContainer(containerId: string, force?: boolean): Promise<void>;
    /** Execute command in container */
    exec(containerId: string, command: string[], options?: DockerExecOptions): Promise<DockerExecResult>;
    /** Get container stats */
    getStats(containerId: string): Promise<DockerStats>;
    /** Get container status */
    getStatus(containerId: string): Promise<ContainerStatus>;
    /** Pull image */
    pullImage(image: string): Promise<void>;
    /** Check if image exists */
    imageExists(image: string): Promise<boolean>;
}
interface DockerContainerConfig {
    image: string;
    name?: string;
    env?: Record<string, string>;
    workDir?: string;
    user?: string;
    networkMode?: string;
    memory?: number;
    cpuShares?: number;
    volumes?: Array<{
        source: string;
        target: string;
        readOnly?: boolean;
    }>;
    labels?: Record<string, string>;
}
interface DockerExecOptions {
    workDir?: string;
    env?: Record<string, string>;
    user?: string;
    stdin?: string;
    timeout?: number;
}
interface DockerExecResult {
    exitCode: number;
    stdout: string;
    stderr: string;
}
interface DockerStats {
    cpuPercent: number;
    memoryUsage: number;
    memoryLimit: number;
    networkRx: number;
    networkTx: number;
    blockRead: number;
    blockWrite: number;
}
/**
 * Mock Docker client for testing when Docker is not available
 */
export declare class MockDockerClient implements IDockerClient {
    private containers;
    isAvailable(): Promise<boolean>;
    createContainer(config: DockerContainerConfig): Promise<string>;
    startContainer(containerId: string): Promise<void>;
    stopContainer(containerId: string, _timeout?: number): Promise<void>;
    removeContainer(containerId: string, _force?: boolean): Promise<void>;
    exec(_containerId: string, command: string[], _options?: DockerExecOptions): Promise<DockerExecResult>;
    getStats(_containerId: string): Promise<DockerStats>;
    getStatus(containerId: string): Promise<ContainerStatus>;
    pullImage(_image: string): Promise<void>;
    imageExists(_image: string): Promise<boolean>;
}
/**
 * Docker Sandbox Manager
 *
 * Manages Docker containers for isolated code execution per session.
 */
export declare class DockerSandboxManager extends EventEmitter {
    private docker;
    private defaultConfig;
    private containers;
    private sessionToContainer;
    private healthCheckTimer;
    constructor(docker?: IDockerClient, config?: Partial<DockerSandboxConfig>);
    /**
     * Initialize the sandbox manager
     */
    initialize(): Promise<void>;
    /**
     * Shutdown the sandbox manager
     */
    shutdown(): Promise<void>;
    /**
     * Create a container for a session
     */
    createContainer(sessionId: string, config?: Partial<DockerSandboxConfig>): Promise<SessionContainer>;
    /**
     * Get container for a session
     */
    getContainerForSession(sessionId: string): SessionContainer | undefined;
    /**
     * Get container by ID
     */
    getContainer(id: string): SessionContainer | undefined;
    /**
     * Get all containers
     */
    getAllContainers(): SessionContainer[];
    /**
     * Destroy a container
     */
    destroyContainer(id: string): Promise<void>;
    /**
     * Destroy container for a session
     */
    destroyContainerForSession(sessionId: string): Promise<void>;
    /**
     * Execute a command in a container
     */
    executeInContainer(id: string, command: string, options?: ExecutionOptions): Promise<ExecutionResult>;
    /**
     * Execute in session's container
     */
    executeInSession(sessionId: string, command: string, options?: ExecutionOptions): Promise<ExecutionResult>;
    /**
     * Set tool allowlist for a container
     */
    setToolAllowlist(id: string, tools: string[]): void;
    /**
     * Set tool denylist for a container
     */
    setToolDenylist(id: string, tools: string[]): void;
    /**
     * Check if a tool is allowed
     */
    isToolAllowed(id: string, tool: string): boolean;
    /**
     * Set network policy for a container
     */
    setNetworkPolicy(id: string, policy: NetworkPolicy): void;
    /**
     * Get container metrics
     */
    getMetrics(id: string): Promise<ContainerMetrics | null>;
    /**
     * Get all container metrics
     */
    getAllMetrics(): Promise<Map<string, ContainerMetrics>>;
    /**
     * Clean up idle containers
     */
    cleanupIdleContainers(maxIdleMs: number): Promise<number>;
    /**
     * Get manager statistics
     */
    getStats(): {
        totalContainers: number;
        runningContainers: number;
        stoppedContainers: number;
        sessionsWithContainers: number;
    };
    private parseMemory;
    private parseCommand;
    private startHealthCheck;
    private stopHealthCheck;
}
/**
 * Get Docker sandbox manager instance
 */
export declare function getDockerSandboxManager(docker?: IDockerClient, config?: Partial<DockerSandboxConfig>): DockerSandboxManager;
/**
 * Reset sandbox manager instance
 */
export declare function resetDockerSandboxManager(): Promise<void>;
export default DockerSandboxManager;
