{"record":{"id":"f02380d563e1a8ff","repo":"Hmbown/CodeWhale","slug":"read-only-executable-path-is-not-valid-utf-8","errorCode":null,"errorMessage":"read-only executable path is not valid UTF-8","messagePattern":"read-only executable path is not valid UTF-8","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/shell.rs","lineNumber":2166,"sourceCode":"        validate_shell_working_dir(&work_dir, working_dir.is_none())?;\n\n        let timeout_ms = timeout_ms.clamp(timeout_bounds_ms.0, timeout_bounds_ms.1);\n\n        // Use override policy if provided, otherwise use the manager's policy\n        let policy = policy_override.unwrap_or_else(|| self.sandbox_policy.clone());\n\n        // Create command spec and prepare sandboxed environment\n        let spec = if let Some(workspace) = readonly_workspace {\n            if command.contains('|') {\n                let piped = hardened_readonly_pipeline(command, workspace)?;\n                CommandSpec::shell(&piped, work_dir.clone(), Duration::from_millis(timeout_ms))\n            } else {\n                let (program, args) = hardened_readonly_argv(command)?;\n                let program = resolve_readonly_program(&program, workspace)?;\n                CommandSpec::program(\n                    program\n                        .to_str()\n                        .ok_or_else(|| anyhow!(\"read-only executable path is not valid UTF-8\"))?,\n                    args,\n                    work_dir.clone(),\n                    Duration::from_millis(timeout_ms),\n                )\n            }\n        } else {\n            CommandSpec::shell(command, work_dir.clone(), Duration::from_millis(timeout_ms))\n        };\n        let spec = spec.with_policy(policy).with_env(extra_env);\n        let exec_env = self.sandbox_manager.prepare(&spec);\n        if matches!(spec.sandbox_policy, ExecutionSandboxPolicy::ReadOnly)\n            && readonly_workspace.is_none()\n        {\n            // Arbitrary code with a read-only policy needs kernel enforcement;\n            // only the separately hardened argv subset may run without it.\n            require_native_readonly_execution(&exec_env)?;\n        }\n","sourceCodeStart":2148,"sourceCodeEnd":2184,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/shell.rs#L2148-L2184","documentation":"When a command runs under the hardened read-only policy, the resolved executable path (a PathBuf/OsStr) must be convertible to valid UTF-8 to be passed as a string program name into CommandSpec. If the resolved path contains non-UTF-8 bytes (e.g. unusual bytes in a directory name), the code refuses with this error rather than silently mis-handling the path.","triggerScenarios":"Running a read-only sandboxed command whose resolved program path — after resolve_readonly_program against the workspace — contains non-UTF-8 bytes, e.g. a binary installed under a directory with Latin-1/invalid-UTF-8 characters in its name.","commonSituations":"PATH pointing at a directory with non-UTF-8 characters; a workspace path created by a tool that wrote raw bytes into filenames; filesystems that permit non-UTF-8 names (common on Linux).","solutions":["Rename the executable and/or its parent directories to use valid UTF-8 names.","Install or reference the binary via a UTF-8-safe path (e.g. symlink it into /usr/local/bin or another ASCII path).","Check PATH and workspace root for non-UTF-8 components and fix the environment; on Unix you can inspect bytes with `path.as_os_str().as_bytes()`."],"exampleFix":"// before\nPATH=/home/user/biné:/usr/bin  # non-UTF-8 dir in PATH resolves tool from bad path\n\n// after\nln -s /opt/tools/bin/mytool /usr/local/bin/mytool\n# then invoke via the UTF-8-safe /usr/local/bin/mytool","handlingStrategy":"validation","validationCode":"// check the resolved program is UTF-8 before running the read-only command\nlet program = resolve_readonly_program(&program, workspace)?;\nif program.to_str().is_none() {\n    return Err(anyhow!(\n        \"executable path {:?} contains non-UTF-8 bytes; rename or symlink it\",\n        program\n    ));\n}","typeGuard":null,"tryCatchPattern":"// catch and guide the user to fix the environment\nmatch run_readonly(command) {\n    Err(e) if e.to_string().contains(\"not valid UTF-8\") => {\n        eprintln!(\"Binary path has non-UTF-8 characters; symlink it to a UTF-8-safe path.\");\n    }\n    other => other?,\n}","preventionTips":["Keep PATH and workspace directories free of non-UTF-8 names.","Symlink non-UTF-8-named binaries into an ASCII path like /usr/local/bin.","Audit environment/workspace paths with a UTF-8 validity check at startup."],"tags":["utf-8","path","shell","sandbox","encoding"],"backgroundTag":"invalid-argument-format","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}