- Added the new codex-windows-sandbox crate that builds both a library
entry point (run_windows_sandbox_capture) and a CLI executable to launch
commands inside a Windows restricted-token sandbox, including ACL
management, capability SID provisioning, network lockdown, and output
capture
(windows-sandbox-rs/src/lib.rs:167, windows-sandbox-rs/src/main.rs:54).
- Introduced the experimental WindowsSandbox feature flag and wiring so
Windows builds can opt into the sandbox:
SandboxType::WindowsRestrictedToken, the in-process execution path, and
platform sandbox selection now honor the flag (core/src/features.rs:47,
core/src/config.rs:1224, core/src/safety.rs:19,
core/src/sandboxing/mod.rs:69, core/src/exec.rs:79,
core/src/exec.rs:172).
- Updated workspace metadata to include the new crate and its
Windows-specific dependencies so the core crate can link against it
(codex-rs/
Cargo.toml:91, core/Cargo.toml:86).
- Added a PowerShell bootstrap script that installs the Windows
toolchain, required CLI utilities, and builds the workspace to ease
development
on the platform (scripts/setup-windows.ps1:1).
- Landed a Python smoke-test suite that exercises
read-only/workspace-write policies, ACL behavior, and network denial for
the Windows sandbox
binary (windows-sandbox-rs/sandbox_smoketests.py:1).
44 lines
1.6 KiB
Rust
44 lines
1.6 KiB
Rust
use std::ffi::OsStr;
|
|
use std::os::windows::ffi::OsStrExt;
|
|
use windows_sys::Win32::Foundation::LocalFree;
|
|
use windows_sys::Win32::Foundation::HLOCAL;
|
|
use windows_sys::Win32::System::Diagnostics::Debug::FormatMessageW;
|
|
use windows_sys::Win32::System::Diagnostics::Debug::FORMAT_MESSAGE_ALLOCATE_BUFFER;
|
|
use windows_sys::Win32::System::Diagnostics::Debug::FORMAT_MESSAGE_FROM_SYSTEM;
|
|
use windows_sys::Win32::System::Diagnostics::Debug::FORMAT_MESSAGE_IGNORE_INSERTS;
|
|
|
|
pub fn to_wide<S: AsRef<OsStr>>(s: S) -> Vec<u16> {
|
|
let mut v: Vec<u16> = s.as_ref().encode_wide().collect();
|
|
v.push(0);
|
|
v
|
|
}
|
|
|
|
// Produce a readable description for a Win32 error code.
|
|
pub fn format_last_error(err: i32) -> String {
|
|
unsafe {
|
|
let mut buf_ptr: *mut u16 = std::ptr::null_mut();
|
|
let flags = FORMAT_MESSAGE_ALLOCATE_BUFFER
|
|
| FORMAT_MESSAGE_FROM_SYSTEM
|
|
| FORMAT_MESSAGE_IGNORE_INSERTS;
|
|
let len = FormatMessageW(
|
|
flags,
|
|
std::ptr::null(),
|
|
err as u32,
|
|
0,
|
|
// FORMAT_MESSAGE_ALLOCATE_BUFFER expects a pointer to receive the allocated buffer.
|
|
// Cast &mut *mut u16 to *mut u16 as required by windows-sys.
|
|
(&mut buf_ptr as *mut *mut u16) as *mut u16,
|
|
0,
|
|
std::ptr::null_mut(),
|
|
);
|
|
if len == 0 || buf_ptr.is_null() {
|
|
return format!("Win32 error {}", err);
|
|
}
|
|
let slice = std::slice::from_raw_parts(buf_ptr, len as usize);
|
|
let mut s = String::from_utf16_lossy(slice);
|
|
s = s.trim().to_string();
|
|
let _ = LocalFree(buf_ptr as HLOCAL);
|
|
s
|
|
}
|
|
}
|