{"record":{"id":"43f77d090e44bc9c","repo":"Hmbown/CodeWhale","slug":"command-failed-with-exit-code-exit-code","errorCode":null,"errorMessage":"Command failed with exit code {exit_code}","messagePattern":"Command failed with exit code (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":9128,"sourceCode":"        let exit_code = status.code().unwrap_or(-1);\n        let sandbox_type = exec_env.sandbox_type;\n        let sandbox_denied = SandboxManager::was_denied(sandbox_type, exit_code, &stderr_str);\n\n        if !stdout.is_empty() {\n            print!(\"{}\", String::from_utf8_lossy(&stdout));\n        }\n        if !stderr.is_empty() {\n            eprint!(\"{stderr_str}\");\n        }\n        if sandbox_denied {\n            eprintln!(\n                \"{}\",\n                SandboxManager::denial_message(sandbox_type, &stderr_str)\n            );\n        }\n\n        if !status.success() {\n            bail!(\"Command failed with exit code {exit_code}\");\n        }\n    } else {\n        let _ = child.kill();\n        let _ = child.wait();\n        bail!(\"Command timed out after {}ms\", timeout.as_millis());\n    }\n    Ok(())\n}\n\nfn parse_sandbox_policy(\n    policy: &str,\n    network: bool,\n    writable_root: Vec<PathBuf>,\n    exclude_tmpdir: bool,\n    exclude_slash_tmp: bool,\n) -> Result<crate::sandbox::SandboxPolicy> {\n    use crate::sandbox::SandboxPolicy;\n","sourceCodeStart":9110,"sourceCodeEnd":9146,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/lib.rs#L9110-L9146","documentation":"The sandboxed exec runner streams the child's stdout/stderr, prints an extra sandbox-denial hint when the sandbox rejected an operation, and finally converts any non-zero child exit into this error carrying the exit code. The child's own output -- the actual cause -- has already been printed above the bail line.","triggerScenarios":"Any sandboxed exec run whose command exits non-zero: a failing build/test/lint inside the sandbox, or a tool that errors because the sandbox denied a write or network access it needed.","commonSituations":"cargo/npm test failures routed through exec; compilers unable to write target/ under a read-only policy; scripts assuming HOME or /tmp writability that the policy excludes.","solutions":["Scroll up: the child's stderr above the bail states the underlying failure","If a sandbox denial line appeared, widen the policy (workspace-write, extra writable roots) or move the writes inside the workspace","Fix the underlying command and re-run","Reproduce the command outside the sandbox to separate policy failures from real failures"],"exampleFix":"# before\ncodewhale exec --sandbox read-only -- cargo build   # writes denied, exit code 101\n\n# after\ncodewhale exec --sandbox workspace-write -- cargo build","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_sandboxed_exec(cmd, policy, timeout) {\n    Err(e) if e.to_string().starts_with(\"Command failed with exit code\") => {\n        // child's real stderr was already streamed; inspect logs, then decide:\n        // policy denial -> widen sandbox; real failure -> fix command\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {},\n}","preventionTips":["Match the sandbox policy to the workload's write needs before running","Log streamed child output so the exit-code wrapper is never your only signal","For untrusted commands prefer a tight policy and expect non-zero exits as the norm"],"tags":["exec","sandbox","exit-code","subprocess"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}