Skip to content

[do not merge] Run shell commands in remote environments#28722

Closed
jif-oai wants to merge 1 commit into
mainfrom
jif/remote-shell-execution
Closed

[do not merge] Run shell commands in remote environments#28722
jif-oai wants to merge 1 commit into
mainfrom
jif/remote-shell-execution

Conversation

@jif-oai

@jif-oai jif-oai commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Why

shell_command still assumes that the Codex orchestrator owns the selected working directory and can spawn the command locally. In a split environment, the primary working directory and shell belong to the remote executor, so the command can run against the wrong filesystem or fail before reaching the executor.

Unified exec already routes commands through the selected environment. This change gives shell_command the same split execution boundary without changing its local execution path.

What this achieves

  • Resolves the command working directory and shell from the primary turn environment.
  • Keeps the existing shell_command approval and sandbox transformation flow.
  • Sends remote commands through the existing unified-exec process lifecycle and environment exec backend.
  • Avoids applying orchestrator-local shell snapshots and runtime path changes to remote commands.
  • Leaves local shell_command execution unchanged.
  • Adds an integration test proving that a remote primary environment reads the remote working directory instead of the local one.

Known limitations

Remote shell_command intentionally supports no more than unified exec currently supports on the split:

  • Remote stdout and stderr are exposed as unified exec's combined output stream; stderr identity is not preserved separately.
  • Timeout and cancellation begin after the remote process is established, and termination uses unified exec's existing output-drain behavior.
  • Sandboxing and platform support are the same as unified exec today. This PR does not improve split sandboxing or Windows support.
  • Remote shell snapshots and the zsh-fork execution path are not supported.
  • Remote paths must currently be representable using the orchestrator's native path convention.

@jif-oai
jif-oai requested a review from a team as a code owner June 17, 2026 12:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e0b7d2d33

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/tools/runtimes/shell.rs
Comment thread codex-rs/core/src/exec/remote.rs Outdated
Comment thread codex-rs/core/src/tools/runtimes/shell.rs
@jif-oai
jif-oai force-pushed the jif/remote-shell-execution branch from 0e0b7d2 to 45bf315 Compare June 17, 2026 13:03
@jif-oai
jif-oai force-pushed the jif/remote-shell-execution branch from 45bf315 to 3c3dd87 Compare June 17, 2026 13:32
@jif-oai

jif-oai commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c3dd87856

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/tools/runtimes/shell.rs
Comment thread codex-rs/core/src/tools/handlers/shell/shell_command.rs
Comment on lines +354 to +361
ctx.session
.services
.unified_exec_manager
.execute_remote_shell(
exec_env,
req.turn_environment.environment.as_ref(),
&context,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Avoid sending host sandbox wrappers to remote shells

For remote environments, this sends the already-transformed exec_env to the exec server, but attempt.env_for(...) above can wrap the argv with the client host's sandbox helper before this branch runs. In a cross-OS remote setup (for example a Linux client controlling a Windows/Wine exec environment) with the default/read-only sandbox selected, the remote side will try to launch a host-specific wrapper such as the Linux sandbox instead of a target-native command and the shell call fails before the user command runs; remote execution needs target-environment sandboxing or to avoid host wrappers.

AGENTS.md reference: AGENTS.md:L306-L308

Useful? React with 👍 / 👎.

@jif-oai jif-oai changed the title Run shell commands in remote environments [do not merge] Run shell commands in remote environments Jun 17, 2026
jif-oai added a commit that referenced this pull request Jun 17, 2026
## Why

Command approval cache keys included the command and working directory,
but not the execution environment. An approval for `/workspace` locally
could therefore be reused for the same command and path on an executor.

## What changed

- Include the selected environment ID in shell and unified-exec approval
cache keys.
- Carry that ID through the normal command approval request so clients
can show which environment is being approved.
- Expose the environment through app-server as a required nullable
`environmentId` and show it in the inline TUI approval prompt.
- Keep older recorded approval events compatible when the environment is
absent.

For example, `echo ok` in local `/workspace` and `echo ok` in executor
`/workspace` now produce different approval keys and separate prompts.

## Scope

This PR does not change network approvals, Guardian review actions, MCP
elicitation, full-screen TUI rendering, or environment-ID validation.
Remote `shell_command` execution itself remains in #28722; this PR only
makes its approval key environment-aware.
wangjiecloud pushed a commit to wangjiecloud/codex that referenced this pull request Jun 27, 2026
## Why

Command approval cache keys included the command and working directory,
but not the execution environment. An approval for `/workspace` locally
could therefore be reused for the same command and path on an executor.

## What changed

- Include the selected environment ID in shell and unified-exec approval
cache keys.
- Carry that ID through the normal command approval request so clients
can show which environment is being approved.
- Expose the environment through app-server as a required nullable
`environmentId` and show it in the inline TUI approval prompt.
- Keep older recorded approval events compatible when the environment is
absent.

For example, `echo ok` in local `/workspace` and `echo ok` in executor
`/workspace` now produce different approval keys and separate prompts.

## Scope

This PR does not change network approvals, Guardian review actions, MCP
elicitation, full-screen TUI rendering, or environment-ID validation.
Remote `shell_command` execution itself remains in openai#28722; this PR only
makes its approval key environment-aware.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Jul 2, 2026
dkropachev pushed a commit to dkropachev/codex that referenced this pull request Jul 5, 2026
## Why

Command approval cache keys included the command and working directory,
but not the execution environment. An approval for `/workspace` locally
could therefore be reused for the same command and path on an executor.

## What changed

- Include the selected environment ID in shell and unified-exec approval
cache keys.
- Carry that ID through the normal command approval request so clients
can show which environment is being approved.
- Expose the environment through app-server as a required nullable
`environmentId` and show it in the inline TUI approval prompt.
- Keep older recorded approval events compatible when the environment is
absent.

For example, `echo ok` in local `/workspace` and `echo ok` in executor
`/workspace` now produce different approval keys and separate prompts.

## Scope

This PR does not change network approvals, Guardian review actions, MCP
elicitation, full-screen TUI rendering, or environment-ID validation.
Remote `shell_command` execution itself remains in openai#28722; this PR only
makes its approval key environment-aware.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant