Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion codex-rs/core/src/tasks/user_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ impl SessionTask for UserShellCommandTask {
let tool_call = ToolCall {
tool_name: USER_SHELL_TOOL_NAME.to_string(),
call_id: Uuid::new_v4().to_string(),
payload: ToolPayload::LocalShell { params },
payload: ToolPayload::LocalShell {
params,
is_user_shell_command: true,
},
};

let router = Arc::new(ToolRouter::from_config(&turn_context.tools_config, None));
Expand Down
3 changes: 2 additions & 1 deletion codex-rs/core/src/tools/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum ToolPayload {
},
LocalShell {
params: ShellToolCallParams,
is_user_shell_command: bool,
},
UnifiedExec {
arguments: String,
Expand All @@ -56,7 +57,7 @@ impl ToolPayload {
match self {
ToolPayload::Function { arguments } => Cow::Borrowed(arguments),
ToolPayload::Custom { input } => Cow::Borrowed(input),
ToolPayload::LocalShell { params } => Cow::Owned(params.command.join(" ")),
ToolPayload::LocalShell { params, .. } => Cow::Owned(params.command.join(" ")),
ToolPayload::UnifiedExec { arguments } => Cow::Borrowed(arguments),
ToolPayload::Mcp { raw_arguments, .. } => Cow::Borrowed(raw_arguments),
}
Expand Down
8 changes: 6 additions & 2 deletions codex-rs/core/src/tools/handlers/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ impl ToolHandler for ShellHandler {
)
.await
}
ToolPayload::LocalShell { params } => {
ToolPayload::LocalShell {
params,
is_user_shell_command,
} => {
let exec_params = Self::to_exec_params(params, turn.as_ref());
Self::run_exec_like(
tool_name.as_str(),
Expand All @@ -91,7 +94,7 @@ impl ToolHandler for ShellHandler {
turn,
tracker,
call_id,
true,
is_user_shell_command,
)
.await
}
Expand Down Expand Up @@ -219,6 +222,7 @@ impl ShellHandler {
env: exec_params.env.clone(),
with_escalated_permissions: exec_params.with_escalated_permissions,
justification: exec_params.justification.clone(),
is_user_shell_command,
};
let mut orchestrator = ToolOrchestrator::new();
let mut runtime = ShellRuntime::new();
Expand Down
5 changes: 4 additions & 1 deletion codex-rs/core/src/tools/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ impl ToolRouter {
Ok(Some(ToolCall {
tool_name: "local_shell".to_string(),
call_id,
payload: ToolPayload::LocalShell { params },
payload: ToolPayload::LocalShell {
params,
is_user_shell_command: false,
},
}))
}
}
Expand Down
6 changes: 5 additions & 1 deletion codex-rs/core/src/tools/runtimes/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct ShellRequest {
pub env: std::collections::HashMap<String, String>,
pub with_escalated_permissions: Option<bool>,
pub justification: Option<String>,
pub is_user_shell_command: bool,
}

impl ProvidesSandboxRetryData for ShellRequest {
Expand Down Expand Up @@ -121,6 +122,9 @@ impl Approvable<ShellRequest> for ShellRuntime {
policy: AskForApproval,
sandbox_policy: &SandboxPolicy,
) -> bool {
if req.is_user_shell_command {
Copy link
Collaborator

@pakrym-oai pakrym-oai Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering we don't need either approvals, or sandbox, or output shape or possibly event events produced by tool calling infrastructure I wonder if we should use execute_exec_env directly in user_shell.

return false;
}
if is_known_safe_command(&req.command) {
return false;
}
Expand All @@ -146,7 +150,7 @@ impl Approvable<ShellRequest> for ShellRuntime {
}

fn wants_escalated_first_attempt(&self, req: &ShellRequest) -> bool {
req.with_escalated_permissions.unwrap_or(false)
req.is_user_shell_command || req.with_escalated_permissions.unwrap_or(false)
}
}

Expand Down
Loading