Skip to content

Windows sandboxed shell commands fail with CreateRestrictedToken failed: 87 even with [windows] sandbox = "unelevated" #18451

Open

Description

@ccstudentcc

What version of Codex CLI is running?

codex-cli 0.119.0-alpha.28

Also reproduced earlier on codex-cli 0.122.0-alpha.1 before downgrading the VS Code extension bundle.

What subscription do you have?

Using the Codex CLI bundled with the VS Code ChatGPT/Codex extension on a logged-in ChatGPT account. Exact subscription tier is not surfaced clearly in the CLI environment.

Which model were you using?

Default model from the current Codex setup; not explicitly overridden for this repro.

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What terminal emulator and version are you using (if applicable)?

PowerShell 7.6.0, launched from a normal non-admin Windows session. No tmux/screen/zellij. The codex binary comes from the VS Code extension bundle.

What issue are you seeing?

Any nested codex exec run that tries to execute even a trivial PowerShell command inside the Windows sandbox fails with:

windows sandbox: CreateRestrictedToken failed: 87

This reproduces with both:

  • --sandbox workspace-write
  • --sandbox read-only

It also reproduces when Windows sandbox mode is explicitly configured as:

[windows]
sandbox = "unelevated"

and also when that setting is passed explicitly via:

-c 'windows.sandbox="unelevated"'

The agent may still continue and produce a text answer, but any shell-backed local file reading/editing path is effectively broken because the command execution step fails first.

Example stderr / JSONL output from the repro:

{"type":"item.completed","item":{"id":"item_0","type":"command_execution","command":"\"C:\\Program Files\\PowerShell\\7\\pwsh.exe\" -Command Get-Location","aggregated_output":"execution error: Io(Custom { kind: Other, error: \"windows sandbox: CreateRestrictedToken failed: 87\" })","exit_code":-1,"status":"failed"}}
2026-04-18T02:36:55.597122Z ERROR codex_core::exec: exec error: windows sandbox: CreateRestrictedToken failed: 87
2026-04-18T02:36:55.600440Z ERROR codex_core::tools::router: error=execution error: Io(Custom { kind: Other, error: "windows sandbox: CreateRestrictedToken failed: 87" })

Related context:

  • current codex path after downgrade:
    • c:\Users\chenpeng\.vscode\extensions\openai.chatgpt-26.409.20454-win32-x64\bin\windows-x86_64\codex.exe
  • current session is not elevated / not running as Administrator
  • the repro is repo-independent and does not rely on any project-specific scripts

What steps can reproduce the bug?

  1. On Windows 11, use the Codex CLI bundled with the VS Code extension.

  2. Ensure the session is a normal non-admin PowerShell session.

  3. Set Windows sandbox mode to unelevated in config:

    [windows]
    sandbox = "unelevated"
  4. Run the following minimal repro:

    @'
    Run exactly one shell command: Get-Location
    Then answer with only the resulting path.
    '@ | codex -a never -c 'windows.sandbox="unelevated"' exec --sandbox workspace-write --skip-git-repo-check --ephemeral --color never --json -C D:\chenpeng\Documents\coding\skills-development -
  5. Observe that the nested shell command fails with:

    windows sandbox: CreateRestrictedToken failed: 87
    
  6. Repeat with --sandbox read-only; the same error still occurs.

Observed thread ids from minimal repros:

  • 019d9e72-ae2e-7ca0-b017-92efdc5aace6 on 0.119.0-alpha.28
  • 019d9e73-2e64-7833-b1c9-9e13e47c82a0 on 0.119.0-alpha.28 (read-only)
  • 019d9e6e-713c-7992-beb5-a260b049ea69 on 0.122.0-alpha.1

What is the expected behavior?

The nested shell command should run normally inside the selected sandbox, or fail with a more specific permission/policy message if the command is actually disallowed.

In particular, setting Windows sandbox mode to unelevated should not still fail at sandbox token creation for a trivial Get-Location command.

Additional information

  • I searched existing openai/codex issues for CreateRestrictedToken, windows sandbox, and unelevated before filing. I found related Windows sandbox issues, but not one with this exact CreateRestrictedToken failed: 87 repro.
  • This is blocking attempts to build a genuinely repo-aware automatic executor on Windows using safe settings like -a never plus --sandbox workspace-write, because the agent cannot reliably execute even basic local shell reads inside nested codex exec.
  • A higher-level symptom is that automation degrades into partial / patch-only behavior: the model may still answer, but it cannot reliably inspect local files through shell execution.

Activity

  1. added
    bug
    CLI
    windows-os
    sandbox
    exec
    on Apr 18, 2026
  2. removed
    CLI
    exec
    on Apr 18, 2026
  3. Teknes-admin commented on Jul 3, 2026

    @Teknes-admin

    I’m seeing the same issue on Windows 11 with codex-cli 0.142.5.

    Config:

    approval_policy = "on-request"
    sandbox_mode = "workspace-write"

    [windows]
    sandbox = "unelevated"

    The shell session is a non-elevated / UAC-filtered admin token: medium integrity, with the Administrators group present as deny-only.

    A trivial read-only local command fails before execution:

    git remote -v
    Codex log line:
    
    Code
    · text
    execution error: Io(Custom { kind: Other, error: "windows sandbox: CreateRestrictedToken failed: 87" })
    Retrying the same command with visible escalation / outside the sandbox works:
    
    Code
    · json
    "sandbox_permissions": "require_escalated"
    So this does not look Git/network/repo-specific. It appears to fail in the Windows sandbox token creation path before the command is executed. Subscribing here because this matches my local repro.
  4. thxSakura commented on Jul 8, 2026

    @thxSakura

    After installing Windows update KB5095093 and rebooting, Codex Desktop shell tool recovered when using windows.sandbox="unelevated". A minimal PowerShell command runs successfully in unelevated mode. However, windows.sandbox="elevated" does not appear to be reliable in this environment, so I cannot say that both sandbox modes are fixed. It is not yet clear whether KB5095093 fixed a Windows sandbox/token-related issue directly, or whether the reboot/sandbox reinitialization cleared stale state.

  5. yuukitachi commented on Oct 2, 2026

    @yuukitachi

    Adding a related observation with [windows] sandbox = "elevated" in a separate environment. These details describe an earlier failed attempt; I have not performed a new reproduction for this comment.

    • Windows build: 26200.
    • Codex CLI version recorded during the investigation: 0.159.2.
    • Execution context: a Codex desktop agent session, with the caller already running under the Codex offline sandbox account.
    • Launching a benign check through codex sandbox against a synthetic workspace failed with CreateRestrictedToken failed: 87, blocking the integration check.
    • The sandbox log inspected for that day did not contain an entry directly explaining this error.
    • In-app /feedback was accepted, but the UI reported that some diagnostic files could not be uploaded.

    Nested token restrictions may be relevant, but the root cause has not been established. Is invoking codex sandbox or non-interactive Codex from an already restricted Codex desktop process supported? If so, what supported repair or execution arrangement preserves the elevated sandbox, filesystem access restrictions, and network restrictions?

    The integration attempt remains stopped. No sandbox weakening or sandbox removal was used to retry it. No raw logs, credentials, private project files, or session identifiers are attached to this public comment.

  6. seesomething99-tech commented on Oct 13, 2026

    @seesomething99-tech

    Additional reproduction / diagnostic evidence from Codex CLI 0.162.1 on Windows build 26200.9550 (normal, non-elevated user session):

    • Effective session recorded sandbox_mode=workspace-write, approval_policy=on-request, and [windows] sandbox = "unelevated"; network restricted.
    • Nested Codex Windows sandbox command failed with windows sandbox failed: CreateRestrictedToken failed: 87.
    • Separately, a Codex temporary argument-alias directory creation under the user profile failed with access denied. A read-only Windows access check showed directory listing allowed but subdirectory creation denied for the current restricted token. This may be a distinct problem rather than the root cause of error 87.
    • Token diagnostics of the current shell: restricted token present, non-elevated. Launching a local Python stdio subprocess directly from that restricted shell preserved the restricted, non-elevated token and exited normally on EOF.
    • This does not establish that an MCP server launched by the Codex host after registration would inherit the same sandbox. We did not register the MCP server or change ACLs, sandbox settings, execution policy, or privilege level.
    • We have not isolated the exact invalid argument to CreateRestrictedToken, so we cannot conclude that nesting restricted tokens is inherently unsupported.

    Could maintainers clarify (1) whether the Windows sandbox launcher is expected to work when invoked from an already restricted Codex shell, (2) a supported way to run local stdio MCP servers with guaranteed unelevated sandbox restrictions, and (3) whether the temporary alias-directory failure is a separate known issue?

    No project names, private paths, credentials, tokens, or full local logs included.

  7. voncastro commented on Oct 21, 2026

    @voncastro

    Windows: nested codex sandbox fails before payload with CreateRestrictedToken error 87; single-level passes

    Environment

    • Codex CLI: 0.163.0-alpha.10.2, desktop-app bundled executable.
    • Executable SHA256: f6dbf48cb70f62649c645f26c87dc9bf84cc36986202dfad8e12fb5b8ca70312.
    • Windows version reported by the runtime: 10.0.26300.0.
    • PowerShell payload: pinned PowerShell 7.6.4, -NoProfile.
    • Host controls start from a normal user PowerShell, with the parent token
      reporting IsTokenRestricted = false. No administrator process is required
      by the repro commands.
    • The saved Windows selector is unelevated. This records the configured
      selector, not an independently authenticated effective-backend observation.

    Observed reproduction

    These commands ran on the host with the exact same CLI executable, in the
    same Git worktree. <CODEX> and <PWSH> represent their absolute paths.
    No configuration or runtime home was changed between commands.

    <CODEX> sandbox -- <PWSH> -NoProfile -Command "Write-Output 'ok'"
      exit 0; output: ok
    
    <CODEX> sandbox -- git rev-parse HEAD
      exit 0; output: the expected worktree HEAD
    
    <CODEX> sandbox -- <CODEX> sandbox -- git rev-parse HEAD
      exit 1; payload does not start:
      WARNING: failed to clean up stale arg0 temp dirs: Access is denied. (os error 5)
      WARNING: proceeding, even though we could not create PATH aliases:
      Access is denied. (os error 5) at path
      "<USER_HOME>\\.codex\\tmp\\arg0-windows\\<TEMP_DIR>"
      windows sandbox failed: CreateRestrictedToken failed: 87
    

    All three captures completed without timeout, truncation or incomplete
    capture. The nested case reproduces the same native error previously seen
    when a workspace-write, approval-never executor launches codex sandbox
    for harmless PowerShell and Git probes. From that executor, explicitly
    selecting the built-in workspace permission profile with managed requirements
    also produced error 87. That explicit-profile control has not been repeated
    from the unrestricted host.

    The documented default sandbox log exists locally but was last modified on
    2026-05-18. A bounded inspection found no current error-87 entries; this old
    log is not offered as evidence for the new reproduction.

    Expected behavior and question

    The nested harmless command should start under the intended permissions, or
    the runtime should report a specific unsupported nesting/configuration
    condition. Which native sandbox implementations support this topology, and
    is there a supported repair for this failure in this build?

    Microsoft's CreateRestrictedToken contract permits a restricted input token;
    error 87 alone does not establish that nested restricted tokens are universally
    unsupported. This report does not identify a particular invalid argument,
    assert a Windows-build regression, or claim a root cause for the alias warnings.

    Minimal follow-up without private project code

    The observed Git reproduction needs only an existing Git repository and the
    installed CLI. It has no dependency on this project's scripts or source.
    For an even smaller follow-up, the same single/nested shape can use
    cmd.exe /d /c echo CODEX_NESTED_OK instead of Git; that payload is proposed
    here and has not yet been run as a host control.

    Acceptance criteria for a runtime repair

    1. Preserve the passing single-level PowerShell and Git controls.
    2. The same installed-runtime single/nested comparison succeeds with the
      expected payload output, without changing runtime homes or broadening
      filesystem/network permissions.
    3. Explicit workspace-profile/managed-requirement controls retain those
      constraints and produce complete captured results.
    4. An actual workspace-write, approval-never executor can run its unchanged
      nested probes. A host-only PASS cannot stand in for this executor result.
    5. Any proposed change of sandbox implementation must document and validate
      detached-child lifetime and applicable network behavior separately. A green
      echo probe alone does not qualify the full workflow or repair the original
      backend defect.

    Official references:

    This report intentionally omits account identifiers, user paths, private
    repository names, project/session identifiers, authentication data and raw
    unredacted attachments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsandboxwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions