Files
codex/codex-rs/mxc-sandbox/src/native.rs
T
johnl-oai c6e29b4fcb Migrate the Windows MXC sandbox to mxc-sdk (#55378)
## What changed

- Replace the separate MXC crates with `mxc-sdk` and adapt request construction to its policy and optional environment fields.
- Preserve the native availability probe by caching successful process security environment creation and startup attribute initialization without launching a process.
- Use the SDK's native denied-path support check and configure Bazel resource compilation for Windows GNU targets.

## Testing

Extend the request construction test to verify that nonempty environments use `Some` and empty environments use `None`.

GitOrigin-RevId: 2765c8fd19ee60661b0ce7cb3cba51acadda201a
2026-10-19 20:54:41 +00:00

41 lines
1.6 KiB
Rust

//! Run an already prepared MXC request with inherited stdio and job ownership.
use anyhow::Context;
use anyhow::Result;
use anyhow::ensure;
use mxc_sdk::mxc_common::logger::Logger;
use mxc_sdk::mxc_common::logger::Mode;
use mxc_sdk::mxc_common::models::ExecutionRequest;
use mxc_sdk::mxc_common::sandbox_process::SandboxBackend;
use mxc_sdk::mxc_common::sandbox_process::StdioMode;
use mxc_sdk::process_container_common::base_container_runner::BaseContainerRunner;
// The ETW functions used by tracelogging are documented Advapi32 exports on
// both Windows toolchains; 1.2.3 leaves their import library to the application.
#[link(name = "advapi32")]
unsafe extern "system" {}
pub(super) fn launch(request: &ExecutionRequest) -> Result<i32> {
ensure!(
!request
.policy
.capabilities
.iter()
.any(|capability| capability.eq_ignore_ascii_case("permissiveLearningMode")),
"MXC native launch does not support permissiveLearningMode"
);
if !request.policy.denied_paths.is_empty() {
ensure!(
BaseContainerRunner::supports_native_denied_paths(),
"this Windows build cannot enforce native MXC deny paths"
);
}
let mut logger = Logger::new(Mode::Buffer);
let mut child = BaseContainerRunner::new()
.spawn(request, &mut logger, StdioMode::Inherit)
.map_err(|error| anyhow::anyhow!("{}", error.error_message))?;
// Do not publish the SDK diagnostic buffer: it may contain command or
// environment data. This wrapper emits only the resulting launch error.
child.wait().context("waiting for the MXC command")
}