diff --git a/codex-rs/core/src/exec_tests.rs b/codex-rs/core/src/exec_tests.rs index 5a13626002..1a4477599d 100644 --- a/codex-rs/core/src/exec_tests.rs +++ b/codex-rs/core/src/exec_tests.rs @@ -2,7 +2,6 @@ use super::*; use codex_protocol::config_types::WindowsSandboxLevel; use codex_protocol::models::PermissionProfile; use codex_sandboxing::SandboxType; -use codex_sandboxing::is_likely_sandbox_denied; use core_test_support::PathBufExt; use core_test_support::PathExt; use pretty_assertions::assert_eq; diff --git a/codex-rs/core/src/tools/runtimes/shell/unix_escalation.rs b/codex-rs/core/src/tools/runtimes/shell/unix_escalation.rs index 12bc229a49..dd0cf0c356 100644 --- a/codex-rs/core/src/tools/runtimes/shell/unix_escalation.rs +++ b/codex-rs/core/src/tools/runtimes/shell/unix_escalation.rs @@ -48,6 +48,7 @@ use codex_sandboxing::SandboxManager; use codex_sandboxing::SandboxTransformRequest; use codex_sandboxing::SandboxType; use codex_sandboxing::SandboxablePreference; +use codex_sandboxing::is_filesystem_sandbox_violation; use codex_sandboxing::record_filesystem_sandbox_violation; use codex_shell_command::bash::parse_shell_lc_plain_commands; use codex_shell_command::bash::parse_shell_lc_single_command_prefix; @@ -1113,7 +1114,8 @@ fn map_exec_result( }))); } - if record_filesystem_sandbox_violation(sandbox, &output).is_some() { + if is_filesystem_sandbox_violation(sandbox, &output) { + record_filesystem_sandbox_violation(sandbox, &output); return Err(ToolError::Codex(CodexErr::Sandbox(SandboxErr::Denied { output: Box::new(output), network_policy_decision: None, diff --git a/codex-rs/sandboxing/src/lib.rs b/codex-rs/sandboxing/src/lib.rs index 59b96b2f3e..d407021fa9 100644 --- a/codex-rs/sandboxing/src/lib.rs +++ b/codex-rs/sandboxing/src/lib.rs @@ -30,6 +30,8 @@ pub use violation::FileSystemSandboxViolation; pub use violation::FileSystemSandboxViolationReason; pub use violation::NetworkSandboxViolation; pub use violation::SandboxViolationEvent; +pub use violation::classify_filesystem_sandbox_violation; +pub use violation::is_filesystem_sandbox_violation; pub use violation::record_filesystem_sandbox_violation; pub use violation::record_network_sandbox_violation; pub use violation::record_sandbox_violation; diff --git a/codex-rs/sandboxing/src/violation.rs b/codex-rs/sandboxing/src/violation.rs index c62a15a3fd..2002c49104 100644 --- a/codex-rs/sandboxing/src/violation.rs +++ b/codex-rs/sandboxing/src/violation.rs @@ -147,14 +147,8 @@ pub fn classify_filesystem_sandbox_violation( None } -/// Preserve the legacy boolean sandbox-denial check for call sites that only need a retry decision. -/// -/// We don't have a fully deterministic way to tell if a command failed because -/// of the sandbox: a command in the user's zshrc file might hit an error, but -/// the command itself might fail or succeed for other reasons. For now, we -/// conservatively check for well known command failure exit codes and also look -/// for common sandbox denial keywords in the command output. -pub fn is_likely_sandbox_denied( +/// Return whether a sandboxed process result represents a filesystem sandbox violation. +pub fn is_filesystem_sandbox_violation( sandbox_type: SandboxType, exec_output: &ExecToolCallOutput, ) -> bool { diff --git a/codex-rs/sandboxing/src/violation_tests.rs b/codex-rs/sandboxing/src/violation_tests.rs index 68b91e2037..c57f7ec87d 100644 --- a/codex-rs/sandboxing/src/violation_tests.rs +++ b/codex-rs/sandboxing/src/violation_tests.rs @@ -36,7 +36,7 @@ fn preserves_legacy_boolean_denial_keywords() { let output = make_exec_output(/*exit_code*/ 1, "", keyword, ""); assert_eq!( - is_likely_sandbox_denied(SandboxType::LinuxSeccomp, &output), + is_filesystem_sandbox_violation(SandboxType::LinuxSeccomp, &output), true, "{keyword}" ); @@ -54,19 +54,19 @@ fn preserves_legacy_boolean_denial_ordering() { let non_sandbox_with_keyword = make_exec_output(/*exit_code*/ 1, "", "Operation not permitted", ""); - assert!(!is_likely_sandbox_denied( + assert!(!is_filesystem_sandbox_violation( SandboxType::LinuxSeccomp, &quick_reject_without_keyword )); - assert!(is_likely_sandbox_denied( + assert!(is_filesystem_sandbox_violation( SandboxType::LinuxSeccomp, &quick_reject_with_keyword )); - assert!(!is_likely_sandbox_denied( + assert!(!is_filesystem_sandbox_violation( SandboxType::LinuxSeccomp, &zero_exit_with_keyword )); - assert!(!is_likely_sandbox_denied( + assert!(!is_filesystem_sandbox_violation( SandboxType::None, &non_sandbox_with_keyword )); @@ -137,7 +137,7 @@ fn classifies_linux_sigsys_exit() { fn preserves_boolean_denial_semantics_for_non_sandbox_mode() { let output = make_exec_output(/*exit_code*/ 1, "", "Operation not permitted", ""); - assert!(!is_likely_sandbox_denied(SandboxType::None, &output)); + assert!(!is_filesystem_sandbox_violation(SandboxType::None, &output)); } #[test]