Skip to content

use framed IPC for elevated command runner#14846

Merged
iceweasel-oai merged 3 commits intomainfrom
windows-one-shot-runner-ipc
Mar 17, 2026
Merged

use framed IPC for elevated command runner#14846
iceweasel-oai merged 3 commits intomainfrom
windows-one-shot-runner-ipc

Conversation

@iceweasel-oai
Copy link
Collaborator

Summary

This is PR 2 of the Windows sandbox runner split.

PR 1 introduced the framed IPC runner foundation and related Windows sandbox infrastructure without changing the active elevated one-shot execution path. This PR switches that elevated one-shot path over to the new runner IPC transport and removes the old request-file bootstrap that PR 1 intentionally left in place.

After this change, ordinary elevated Windows sandbox commands still behave as one-shot executions, but they now run as the simple case of the same helper/IPC transport that later unified_exec work will build on.

Why this is needed for unified_exec

Windows elevated sandboxed execution crosses a user boundary: the CLI launches a helper as the sandbox user and has to manage command execution from outside that security context. For one-shot commands, the old request-file/bootstrap flow was sufficient. For unified_exec, it is not.

Unified_exec needs a long-lived bidirectional channel so the parent can:

  • send a spawn request
  • receive structured spawn success/failure
  • stream stdout and stderr incrementally
  • eventually support stdin writes, termination, and other session lifecycle events

This PR does not add long-lived sessions yet. It converts the existing elevated one-shot path to use the same framed IPC transport so that PR 3 can add unified_exec session semantics on top of a transport that is already exercised by normal elevated command execution.

Scope

This PR:

  • updates windows-sandbox-rs/src/elevated_impl.rs to launch the runner with named pipes, send a framed SpawnRequest, wait for SpawnReady, and collect framed Output/Exit messages
  • removes the old --request-file=... execution path from windows-sandbox-rs/src/elevated/command_runner_win.rs
  • keeps the public behavior one-shot: no session reuse or interactive unified_exec behavior is introduced here

This PR does not:

  • add Windows unified_exec session support
  • add background terminal reuse
  • add PTY session lifecycle management

Why Windows needs this and Linux/macOS do not

On Linux and macOS, the existing sandbox/process model composes much more directly with long-lived process control. The parent can generally spawn and own the child process (or PTY) directly inside the sandbox model we already use.

Windows elevated sandboxing is different. The parent is not directly managing the sandboxed process in the same way; it launches across a different user/security context. That means long-lived control requires an explicit helper process plus IPC for spawn, output, exit, and later stdin/session control.

So the extra machinery here is not because unified_exec is conceptually different on Windows. It is because the elevated Windows sandbox boundary requires a helper-mediated transport to support it cleanly.

Validation

  • cargo test -p codex-windows-sandbox

@iceweasel-oai iceweasel-oai changed the title windows-sandbox: switch elevated one-shot runner to IPC use framed IPC for elevated command runner Mar 16, 2026
@iceweasel-oai
Copy link
Collaborator Author

@codex review

Copy link
Contributor

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

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: 8119d7e847

ℹ️ 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".

// PIPE_ACCESS_DUPLEX is 0x00000003; not exposed in windows-sys 0.52, so use the value directly.
const PIPE_ACCESS_DUPLEX: u32 = 0x0000_0003;
const PIPE_ACCESS_INBOUND: u32 = 0x0000_0001;
const PIPE_ACCESS_OUTBOUND: u32 = 0x0000_0002;
Copy link
Collaborator

Choose a reason for hiding this comment

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

sanity-check: PIPE_ACCESS_DUPLEX is not exposed in windows-sys 0.52, but are these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

they also are not

return Err(err.into());
}

let result = (|| -> Result<CaptureResult> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

since we're doing a read loop in this block, should it be on its own thread? or are we planning to handle that in a follow-up unified exec PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep - this is for the non-pty/unified_exec version only

@iceweasel-oai iceweasel-oai merged commit 95bdea9 into main Mar 17, 2026
32 checks passed
@iceweasel-oai iceweasel-oai deleted the windows-one-shot-runner-ipc branch March 17, 2026 18:38
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants