openai/codex · error · anyhow::Error

CreateDesktopW failed

Error message

CreateDesktopW failed: {err}

What it means

CreateDesktopW returned a null handle while creating the private desktop object used to isolate the sandboxed process. GetLastError is captured and also written to the debug log with a formatted description; without a private desktop the sandbox cannot launch, so the error aborts desktop setup.

Solutions

  1. Check the GetLastError code in the message (and the debug log line) for the creation failure
  2. Ensure the caller has window-station/desktop creation rights (DESKTOP_ALL_ACCESS) — run elevated if needed
  3. Close leaking desktop objects if the session desktop heap is exhausted, or reboot to free desktop heap space
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/windows-sandbox-rs/src/desktop.rs:114 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/babadcb5e10d3201. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/windows-sandbox-rs/src/desktop.rs:114

                name_wide.as_ptr(),
                ptr::null(),
                ptr::null_mut(),
                0,
                DESKTOP_ALL_ACCESS,
                ptr::null_mut(),
            )
        };
        if handle == 0 {
            let err = unsafe { GetLastError() } as i32;
            logging::debug_log(
                &format!(
                    "CreateDesktopW failed for {name}: {} ({})",
                    err,
                    format_last_error(err),
                ),
                logs_base_dir,
            );
            return Err(anyhow::anyhow!("CreateDesktopW failed: {err}"));
        }

        unsafe {
            if let Err(err) = grant_desktop_access(handle, logs_base_dir) {
                let _ = CloseDesktop(handle);
                return Err(err);
            }
        }

        Ok(Self { handle, name })
    }
}

unsafe fn grant_desktop_access(handle: isize, logs_base_dir: Option<&Path>) -> Result<()> {
    let token = get_current_token_for_restriction()?;
    let mut logon_sid = get_logon_sid_bytes(token)?;
    CloseHandle(token);

View on GitHub (pinned to 339751715c)