Skip to content

Commit 67975ed

Browse files
authored
refactor: inline sandbox type lookup in process_exec_tool_call (#7122)
`process_exec_tool_call()` was taking `SandboxType` as a param, but in practice, the only place it was constructed was in `codex_message_processor.rs` where it was derived from the other `sandbox_policy` param, so this PR inlines the logic that decides the `SandboxType` into `process_exec_tool_call()`. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/7122). * #7112 * __->__ #7122
1 parent 7561a6a commit 67975ed

File tree

5 files changed

+8
-18
lines changed

5 files changed

+8
-18
lines changed

codex-rs/app-server/src/codex_message_processor.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ use codex_core::exec::ExecParams;
116116
use codex_core::exec_env::create_env;
117117
use codex_core::features::Feature;
118118
use codex_core::find_conversation_path_by_id_str;
119-
use codex_core::get_platform_sandbox;
120119
use codex_core::git_info::git_diff_to_remote;
121120
use codex_core::parse_cursor;
122121
use codex_core::protocol::EventMsg;
@@ -1182,13 +1181,6 @@ impl CodexMessageProcessor {
11821181
.sandbox_policy
11831182
.unwrap_or_else(|| self.config.sandbox_policy.clone());
11841183

1185-
let sandbox_type = match &effective_policy {
1186-
codex_core::protocol::SandboxPolicy::DangerFullAccess => {
1187-
codex_core::exec::SandboxType::None
1188-
}
1189-
_ => get_platform_sandbox().unwrap_or(codex_core::exec::SandboxType::None),
1190-
};
1191-
tracing::debug!("Sandbox type: {sandbox_type:?}");
11921184
let codex_linux_sandbox_exe = self.config.codex_linux_sandbox_exe.clone();
11931185
let outgoing = self.outgoing.clone();
11941186
let req_id = request_id;
@@ -1197,7 +1189,6 @@ impl CodexMessageProcessor {
11971189
tokio::spawn(async move {
11981190
match codex_core::exec::process_exec_tool_call(
11991191
exec_params,
1200-
sandbox_type,
12011192
&effective_policy,
12021193
sandbox_cwd.as_path(),
12031194
&codex_linux_sandbox_exe,

codex-rs/core/src/exec.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use tokio_util::sync::CancellationToken;
1919
use crate::error::CodexErr;
2020
use crate::error::Result;
2121
use crate::error::SandboxErr;
22+
use crate::get_platform_sandbox;
2223
use crate::protocol::Event;
2324
use crate::protocol::EventMsg;
2425
use crate::protocol::ExecCommandOutputDeltaEvent;
@@ -127,12 +128,17 @@ pub struct StdoutStream {
127128

128129
pub async fn process_exec_tool_call(
129130
params: ExecParams,
130-
sandbox_type: SandboxType,
131131
sandbox_policy: &SandboxPolicy,
132132
sandbox_cwd: &Path,
133133
codex_linux_sandbox_exe: &Option<PathBuf>,
134134
stdout_stream: Option<StdoutStream>,
135135
) -> Result<ExecToolCallOutput> {
136+
let sandbox_type = match &sandbox_policy {
137+
SandboxPolicy::DangerFullAccess => SandboxType::None,
138+
_ => get_platform_sandbox().unwrap_or(SandboxType::None),
139+
};
140+
tracing::debug!("Sandbox type: {sandbox_type:?}");
141+
136142
let ExecParams {
137143
command,
138144
cwd,
@@ -893,7 +899,6 @@ mod tests {
893899
});
894900
let result = process_exec_tool_call(
895901
params,
896-
SandboxType::None,
897902
&SandboxPolicy::DangerFullAccess,
898903
cwd.as_path(),
899904
&None,

codex-rs/core/tests/suite/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async fn run_test_cmd(tmp: TempDir, cmd: Vec<&str>) -> Result<ExecToolCallOutput
4141

4242
let policy = SandboxPolicy::new_read_only_policy();
4343

44-
process_exec_tool_call(params, sandbox_type, &policy, tmp.path(), &None, None).await
44+
process_exec_tool_call(params, &policy, tmp.path(), &None, None).await
4545
}
4646

4747
/// Command succeeds with exit code 0 normally

codex-rs/exec-server/src/posix/escalate_server.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use std::time::Duration;
88
use anyhow::Context as _;
99
use path_absolutize::Absolutize as _;
1010

11-
use codex_core::exec::SandboxType;
1211
use codex_core::exec::process_exec_tool_call;
13-
use codex_core::get_platform_sandbox;
1412
use codex_core::protocol::SandboxPolicy;
1513
use tokio::process::Command;
1614
use tokio_util::sync::CancellationToken;
@@ -96,7 +94,6 @@ impl EscalateServer {
9694
justification: None,
9795
arg0: None,
9896
},
99-
get_platform_sandbox().unwrap_or(SandboxType::None),
10097
&sandbox_policy,
10198
&sandbox_cwd,
10299
&None,

codex-rs/linux-sandbox/tests/suite/landlock.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use codex_core::config::types::ShellEnvironmentPolicy;
33
use codex_core::error::CodexErr;
44
use codex_core::error::SandboxErr;
55
use codex_core::exec::ExecParams;
6-
use codex_core::exec::SandboxType;
76
use codex_core::exec::process_exec_tool_call;
87
use codex_core::exec_env::create_env;
98
use codex_core::protocol::SandboxPolicy;
@@ -60,7 +59,6 @@ async fn run_cmd(cmd: &[&str], writable_roots: &[PathBuf], timeout_ms: u64) {
6059
let codex_linux_sandbox_exe = Some(PathBuf::from(sandbox_program));
6160
let res = process_exec_tool_call(
6261
params,
63-
SandboxType::LinuxSeccomp,
6462
&sandbox_policy,
6563
sandbox_cwd.as_path(),
6664
&codex_linux_sandbox_exe,
@@ -155,7 +153,6 @@ async fn assert_network_blocked(cmd: &[&str]) {
155153
let codex_linux_sandbox_exe: Option<PathBuf> = Some(PathBuf::from(sandbox_program));
156154
let result = process_exec_tool_call(
157155
params,
158-
SandboxType::LinuxSeccomp,
159156
&sandbox_policy,
160157
sandbox_cwd.as_path(),
161158
&codex_linux_sandbox_exe,

0 commit comments

Comments
 (0)