openai/codex · error · anyhow::Error

sandbox dir failed

Error message

{api} sandbox dir failed: {res}

What it means

Applying the newly built DACL to the sandbox directory failed: depending on which branch ran, either SetKernelObjectSecurity (on the held no-reparse handle) or SetNamedSecurityInfoW (on the path) returned a nonzero status. The message names the exact API that failed, so the sandbox directory remains without the intended restrictive ACL.

Solutions

  1. Decode the returned Win32 error to distinguish access-denied (needs elevation) from invalid-owner/privilege errors
  2. Run the setup binary elevated so SE_SECURITY_PRIVILEGE and WRITE_DAC on the directory are available
  3. If ownership is the issue, take ownership of the sandbox directory as administrator and re-run setup
  4. Check the named branch only fires when no handle was available; prefer re-running so the handle-based branch is used
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs:405 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/2d31d10f4da5a255. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs:405

            ),
            None => {
                let path_w = to_wide(dir.as_os_str());
                (
                    SetNamedSecurityInfoW(
                        path_w.as_ptr() as *mut u16,
                        SE_FILE_OBJECT,
                        DACL_SECURITY_INFORMATION,
                        std::ptr::null_mut(),
                        std::ptr::null_mut(),
                        new_dacl,
                        std::ptr::null_mut(),
                    ),
                    "SetNamedSecurityInfoW",
                )
            }
        };
        if res != 0 {
            return Err(anyhow::anyhow!("{api} sandbox dir failed: {res}"));
        }
        if !new_dacl.is_null() {
            LocalFree(new_dacl as HLOCAL);
        }
        for sid in sids {
            if !sid.is_null() {
                LocalFree(sid as HLOCAL);
            }
        }
    }
    Ok(())
}

pub fn main() -> Result<()> {
    let ret = real_main();
    if let Err(e) = &ret {
        // Best-effort: log unexpected top-level errors.
        if let Ok(codex_home) = std::env::var("CODEX_HOME") {

View on GitHub (pinned to 339751715c)