/**
 * Sandboxed BashOperations implementation.
 *
 * Uses SandboxManager.wrapCommand() to build the sandboxed command,
 * then owns the process lifecycle (spawn, kill, stream, timeout).
 */
import { spawn } from 'child_process';
import { manageChildProcess } from '../../shared/process/lifecycle.js';
import { toLinuxPath } from './lib/index.js';
/**
 * Create a BashOperations that runs commands inside a WSL2 + bwrap sandbox.
 *
 * The manager builds the command (with proxy socket + cwd); this function owns spawning it.
 * Awaits manager.ensureReady() before the first command to prevent proxy startup races.
 */
export function createSandboxOperations(manager) {
    return {
        exec: async (command, cwd, { onData, signal, timeout }) => {
            // Wait for proxy to be ready before first command
            await manager.ensureReady();
            const linuxCwd = cwd ? toLinuxPath(cwd) : undefined;
            const wrapped = manager.wrapCommand(command, linuxCwd);
            const child = spawn(wrapped.file, wrapped.args, {
                stdio: ['ignore', 'pipe', 'pipe'],
                windowsHide: true
            });
            return manageChildProcess(child, { onData, signal, timeout });
        }
    };
}
//# sourceMappingURL=sandbox-executor.js.map