codex icon indicating copy to clipboard operation
codex copied to clipboard

Windows sandbox leaks kernel token objects (~3 GB paged pool after a day of use)

Open Big-P-Dev opened this issue 1 week ago • 2 comments

Windows sandbox leaks kernel token objects (~3 GB paged pool after a day of use)

Summary

On Windows, the Codex sandbox logs on its sandbox users (CodexSandboxOnline / CodexSandboxOffline) through the Secondary Logon service for each sandboxed command. The token objects from those logons are never freed. After about 2,000 sandbox logons, 1.1 million token objects were still live in kernel paged pool, about 3 GB in all, with no process holding handles to them. The memory is only freed by a reboot.

Environment

  • Windows 11 Pro, build 26300, 32 GB RAM
  • Codex with the Windows sandbox enabled, several concurrent agent sessions
  • Uptime at measurement: 55 h

Evidence

Kernel pool by tag (NtQuerySystemInformation(SystemPoolTagInformation); the same data poolmon shows):

Tag Paged MB Live allocations
Toke 2,327 1,113,345
SeAt 410 4,473,010
SeTd 155 1,113,345
SeDt 84 1,101,115
  • Total paged pool was 6.0 GB. A healthy system shows well under 1 GB.
  • Total open handles system-wide were about 140,000. The highest were System at 35k and lsass at 22k. The leaked tokens are therefore kernel references, not handles a process holds.
  • Process (Proc) and thread (Thre) objects are not leaked. Starting and exiting 80 ordinary processes changed the token count by 0.

Security log, event 4624 (successful logon), over the last 56 h:

Count Logon type User Logon process Caller
1,451 2 (interactive) CodexSandboxOnline seclogo svchost.exe (Secondary Logon)
538 2 (interactive) CodexSandboxOffline seclogo svchost.exe
32 5 (service) SYSTEM Advapi services.exe

The sandbox logons were concentrated in the hours when Codex jobs ran: 785, 457, 443, 248 and 88 per hour. They stopped when Codex use stopped. Token growth stopped at the same time, and the leaked total stayed constant afterwards.

Steps to reproduce

  1. Run Codex on Windows with the sandbox on, and let it execute many shell commands. Each command produces a 4624 logon for a CodexSandbox* user.
  2. Sample the Toke pool tag (poolmon) before and after.
  3. The live Toke count grows with sandbox logons and never returns after the commands or sessions end.

Expected

Each sandbox logon's token, its logon session and its linked or restricted tokens are released when the sandboxed process exits.

Actual

Tokens accumulate at roughly 550 per sandbox logon (1.1M tokens / ~2,000 logons) and stay until reboot. On a 32 GB machine this cost about 3 GB, or about 10% of RAM, in one working day.

Suspected cause

Per-command interactive logons through Secondary Logon (seclogo), with token references kept alive. Possible ways that happens:

  • the logon session is never ended, so its tokens stay referenced;
  • token handles in the sandbox broker are not closed;
  • a long-lived helper keeps a reference to each logon session.

Reusing a single sandbox logon per session instead of one per command would also cut the rate sharply.

Big-P-Dev avatar Nov 21 '26 17:11 Big-P-Dev

Another data point from a Windows machine, in case it helps pin this down.

Environment: Codex 0.167.0, Windows 11 build 26300 (UBR 9974), elevated sandbox (CodexSandboxOnline / CodexSandboxOffline accounts).

Measurements after 7 days of uptime:

  • About 5,800 type-2 logon sessions belonging to the two sandbox accounts.
  • About 1.15 new logon sessions per sandboxed command (303 commands produced 349 new sessions).
  • Kernel pool tagged Toke/SeTl (token objects) is about 1.3 GB.
  • The leaked sessions hold no processes, so nothing is left running; the sessions and tokens are simply never released.
  • Only a reboot frees them.

So the leak appears to scale with the number of sandboxed commands: each command creates a logon session that is never logged off.

mack-shippen avatar Nov 28 '26 18:11 mack-shippen

One more data point, matching the summary above. Codex desktop app 26.1120.6357.0, Windows 11 Pro build 26300, 32 GB RAM, about 3.7 days up since the last restart.

  • Win32_LogonSession: 3,071 sessions for CodexSandboxOffline, logon type 2 (interactive), NTLM. That is 98.6% of all logon sessions on the machine. They pile up at 100 to 225 an hour while sandboxed commands run, and none ends.
  • Paged pool, from SystemPoolTagInformation: Toke 2,058 MB (938,366 live), SeAt 1,099 MB, SeTd 128 MB (938,366 live). Total paged pool is 8.25 GB.
  • Token handles system-wide: 4,646, most of them in lsass. So, as reported above, no process holds the leaked tokens.
  • Restarting CodexSandboxService.OpenAI.Codex freed nothing: paged pool read the same 30 s later, with the same session count. Only a full restart recovers it. A restart 3.7 days earlier took paged pool from 7.2 GB to 0.7 GB.

The sessions look like the thing to chase: each sandbox logon's session is never torn down, so its tokens stay referenced.

TheOriginalOcyrus avatar Nov 28 '26 18:11 TheOriginalOcyrus