openai/codex · error

AdjustTokenPrivileges error

Error message

AdjustTokenPrivileges error {err}

What it means

AdjustTokenPrivileges succeeded but GetLastError is nonzero — normally ERROR_NOT_ALL_ASSIGNED, meaning the process does not hold the privilege being enabled (common when not elevated), so the privilege was not actually granted.

Solutions

  1. Run the operation from an elevated process that holds the required privilege
  2. If the privilege is optional for the sandbox path, tolerate its absence rather than failing
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/windows-sandbox-rs/src/token.rs:345 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/fdfbf43da1c2f1bb. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/windows-sandbox-rs/src/token.rs:345

    }
    let mut tp: TOKEN_PRIVILEGES = std::mem::zeroed();
    tp.PrivilegeCount = 1;
    tp.Privileges[0].Luid = luid;
    tp.Privileges[0].Attributes = 0x00000002; // SE_PRIVILEGE_ENABLED
    let ok2 = AdjustTokenPrivileges(
        h_token,
        0,
        &tp,
        0,
        std::ptr::null_mut(),
        std::ptr::null_mut(),
    );
    if ok2 == 0 {
        return Err(anyhow!("AdjustTokenPrivileges failed: {}", GetLastError()));
    }
    let err = GetLastError();
    if err != 0 {
        return Err(anyhow!("AdjustTokenPrivileges error {err}"));
    }
    Ok(())
}

/// # Safety
/// Caller must close the returned token handle.
pub unsafe fn create_readonly_token_with_cap(
    psid_capability: *mut c_void,
) -> Result<(HANDLE, *mut c_void)> {
    let base = get_current_token_for_restriction()?;
    let res = create_readonly_token_with_cap_from(base, psid_capability);
    CloseHandle(base);
    res
}

/// # Safety
/// Caller must close the returned token handle; base_token must be a valid primary token.
/// # Safety

View on GitHub (pinned to 339751715c)