{"record":{"id":"3532e6988b525924","repo":"Hmbown/CodeWhale","slug":"failed-to-run-command-e","errorCode":null,"errorMessage":"Failed to run command: {e}","messagePattern":"Failed to run command: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":8931,"sourceCode":"\n    let (program, args) = command\n        .split_first()\n        .ok_or_else(|| anyhow::anyhow!(\"Command is required\"))?;\n    let spec =\n        CommandSpec::program(program, args.to_vec(), cwd.clone(), timeout).with_policy(policy);\n    let manager = SandboxManager::new();\n    let exec_env = manager.prepare(&spec);\n\n    let mut cmd = Command::new(exec_env.program());\n    cmd.args(exec_env.args())\n        .current_dir(&exec_env.cwd)\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped());\n    child_env::apply_to_command(&mut cmd, child_env::string_map_env(&exec_env.env));\n\n    let mut child = cmd\n        .spawn()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run command: {e}\"))?;\n    let stdout_handle = child\n        .stdout\n        .take()\n        .ok_or_else(|| anyhow::anyhow!(\"stdout unavailable\"))?;\n    let stderr_handle = child\n        .stderr\n        .take()\n        .ok_or_else(|| anyhow::anyhow!(\"stderr unavailable\"))?;\n\n    let timeout = exec_env.timeout;\n    let stdout_thread = std::thread::spawn(move || {\n        let mut reader = stdout_handle;\n        let mut buf = Vec::new();\n        let _ = reader.read_to_end(&mut buf);\n        buf\n    });\n    let stderr_thread = std::thread::spawn(move || {\n        let mut reader = stderr_handle;","sourceCodeStart":8913,"sourceCodeEnd":8949,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/lib.rs#L8913-L8949","documentation":"Thrown when std::process::Command::spawn fails while starting the sandboxed child process. The wrapped io::Error is usually NotFound (program not on PATH or bad absolute path), PermissionDenied (file lacks the execute bit, or no interpreter for a script), or a failure resolving exec_env.cwd which is passed to current_dir.","triggerScenarios":"Sandbox run with a program name absent from the child environment's PATH, an absolute/relative path whose file is not executable, a script without a shebang line, or a cwd (explicit argument or the current-dir fallback) that was deleted.","commonSituations":"Typos in tool names inside sandbox configs, PATH shims (nvm, virtualenv) missing from the sanitized child environment, files copied without exec bits (git on FAT, container layers with masked permissions), running from a deleted working directory.","solutions":["Verify the program resolves the same way the sandbox will: run `which <program>` with the child's PATH","chmod +x the target binary or script, and give interpreted scripts a valid shebang","Use an absolute path to the program in the sandbox command configuration","Confirm the cwd passed to the run exists and is a directory (recreate it or pass an absolute cwd)"],"exampleFix":"# before: relative script without exec bit\nsandbox run -- ./tools/lint.sh\n# after\nchmod +x /repo/tools/lint.sh\nsandbox run -- /repo/tools/lint.sh","handlingStrategy":"try-catch","validationCode":"// Rust: resolve the program before spawning\nfn resolvable(program: &str) -> bool {\n    let p = std::path::Path::new(program);\n    if p.is_absolute() || p.components().count() > 1 {\n        p.is_file()\n    } else {\n        std::env::var_os(\"PATH\").map_or(false, |paths| {\n            std::env::split_paths(&paths).any(|dir| dir.join(program).is_file())\n        })\n    }\n}","typeGuard":null,"tryCatchPattern":"match cmd.spawn() {\n    Ok(child) => { /* proceed with pipes and wait */ }\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => { /* program missing from PATH: log resolved PATH and cwd */ }\n    Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => { /* chmod +x or fix shebang */ }\n    Err(e) => return Err(anyhow::anyhow!(\"Failed to run command: {e}\")),\n}","preventionTips":["Prefer absolute program paths in sandbox command configs","Set exec bits explicitly in CI images and Dockerfiles","Keep a shebang on interpreted scripts","Log the PATH and cwd used for the child when spawn fails to speed diagnosis"],"tags":["process","sandbox","os","spawn","permissions"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}