Skip to content

Windows: codex sandbox leaks one logon session per invocation (lsass grows until reboot) #35940

Open

Description

@Darkplates

codex sandbox leaks one Windows logon session per invocation

Reporter: Pedro Bento
Platform: Windows 11 Pro 26200
Versions affected: codex-cli 0.144.3 and 0.146.0 (both measured)

Summary

On Windows, every codex sandbox invocation creates an interactive logon
session for the CodexSandboxOffline sandbox account and never releases it.
The sessions accumulate inside lsass.exe for the lifetime of the boot. Because
lsass cannot be restarted, the only way to reclaim them is a reboot.

After 23 hours of automated use this machine held 15 510 orphaned logon
sessions
and lsass had grown to 79 396 handles. The symptom is
progressive, whole-desktop slowness — dragging, minimising and maximising
windows become visibly laggy — that persists after every Codex process has
exited and disappears only on reboot.

codex exec does not leak. Only codex sandbox does.

Evidence

Security event 4624 for the leaked sessions:

LogonType                 2   (Interactive)
LogonProcessName          seclogo          (Secondary Logon service, in svchost)
AuthenticationPackageName Negotiate
TargetUserName            CodexSandboxOffline

The sessions are orphaned — enumerating Win32_LogonSession and associating to
Win32_Process returns no process for any of them. No process on the machine
holds a comparable handle count, so nothing but lsass is retaining them:

lsass     79 396 handles
System    22 068
explorer   8 253
codex       3 296

Not a profile-hive leak: HKEY_USERS holds 6 keys and no C:\Users\CodexSandbox*
profile directories exist.

Reproduction

function N { (Get-CimInstance Win32_LogonSession).Count }
$before = N
1..20 | ForEach-Object {
  codex sandbox -P :workspace -c windows.sandbox="elevated" -- cmd /c exit 0
}
"leaked: $((N) - $before)"

Measured with paired idle blocks before and after to subtract background:

version mode leaked per invocation
0.144.3 elevated 0.9 – 1.5
0.146.0 elevated 0.66
0.144.3 / 0.146.0 unelevated 0

A short 6-invocation run can read as zero — the measurement needs enough
invocations, and idle control blocks on both sides, to clear the noise.

codex exec --sandbox workspace-write -c windows.sandbox="elevated" running a
shell command leaks nothing, which is what makes the asymmetry look like a
missing handle close on the codex sandbox path specifically rather than in
sandbox setup generally.

Why unelevated is not a workaround

unelevated does not leak, but on both versions it:

  • leaves the network reachable even with --sandbox-state-disable-network
    (a TCP connect to 1.1.1.1:443 succeeds inside the sandbox), and
  • kills child processes created with piped stdio —
    node -e "require('child_process').execSync('node -v', {stdio:'pipe'})"
    fails with spawnSync ... EPERM, which breaks node --test and similar
    runners.

elevated blocks the network correctly (EACCES) and allows piped spawns, so
it is the only usable mode — and it is the one that leaks.

Impact

Any automated use that invokes codex sandbox per command accumulates this
quickly. At roughly 668 sessions/hour on this workload the machine reaches
five figures within a day, and the degradation is indistinguishable from a
general "Windows is slow" problem, which makes it very hard to attribute. It
took a full day of elimination — GPU, VRAM, DWM, MPO, GDI handles, disk,
memory pressure — before the logon-session count was measured.

Expected

codex sandbox should release the logon session it creates when the sandboxed
command exits, or reuse a single session across invocations.

Activity

  1. added
    bug
    CLI
    windows-os
    sandbox
    on Jul 29, 2026
  2. Darkplates commented on Jul 29, 2026

    @Darkplates
    Author

    Cross-referencing: this is very likely the same underlying defect as #33356
    (handle growth per sandboxed command), and probably related to #34062 (profile
    load per command) and #34575 (lost logon session / error 1312). Maintainers may
    want to consolidate.

    What this report adds beyond #33356 is the mechanism and the accounting: the
    growth is one logon session per codex sandbox invocation, created through
    the Secondary Logon service (event 4624, LogonProcessName seclogo, target
    CodexSandboxOffline) and never released, which is why the handle count in
    lsass tracks it at roughly 5 handles per session and why only a reboot clears
    it. It also isolates the asymmetry — codex exec running shell commands does
    not leak, only codex sandbox does — which should narrow where the missing
    release is.

  3. Darkplates commented on Jul 29, 2026

    @Darkplates
    Author

    Follow-up with a finding that should help reproduction: the leak is
    state-dependent, not constant.

    After a reboot cleared the 15 510 accumulated sessions, the same
    measurements that reliably leaked before now leak nothing:

    • 8 × codex sandbox -P :workspace -c windows.sandbox="elevated" on the
      fresh boot: 0 sessions leaked (pre-reboot: the same batch leaked 5-12).
    • One hour of automated workload (BENTO queue, 9 concurrent tasks, including
      10 sandbox invocations): 0 sessions leaked, lsass steady around
      1 500-3 000 handles. Pre-reboot the same workload leaked 668-1080/hour.

    So a fresh lsass releases the CodexSandboxOffline logon sessions
    correctly, and something later tips it into never releasing them; once that
    happens, every launch strands one session and only a reboot recovers. The
    trigger is what I cannot isolate from outside -- uptime, a session-count
    threshold, or some failed cleanup that flips the behaviour. The 22-hour
    uptime figures in the original report describe the degraded regime.

    Practical implication for anyone measuring: a short test on a fresh machine
    will conclude "no leak" and be wrong an hour or a day later. Watching
    (Get-CimInstance Win32_LogonSession).Count over time is the reliable
    signal.

  4. MajesticMug commented on Aug 26, 2026

    @MajesticMug

    Bump

    This is causing severe performance issues during long sessions and the only way to release those orphaned resources is through a PC restart.

    This should be a higher priority!

  5. Darkplates commented on Aug 26, 2026

    @Darkplates
    Author

    I will be honest about this: I am now running Codex on 2 different computers and both have the same issue - I'm LOVING codex with 5.6 sol Ultra.. but the ammount of subagents it calls for and the tasks they run... my new computer (5080 with ryzen 7 7800x3d, 32gb DDR5 6000) still needs to be restarted every 4-5 hours if I want to run Codex on ultra. I'm unclear how prevalent this bug is in codex CLI, but using Codex windows app I can guarantee it's unbearable.

    I understand this might not be affecting all users, but I'm choosing to mantain an OpenAI first envoirement - Codex windows app is vital for this. And this should be something OpenAI should strive for, allowing a user to remain in their ecosystem. Right now I paid 3k€ for a new computer and I still need stop everything and restart every 6 hours if I want to avoid going down to 0.3-0.6 fps. It makes close to 0 sense, specially the lack of replies, considering this is an issue that has been raised in multiple tickets, from multiple people.

  6. MajesticMug commented on Aug 26, 2026

    @MajesticMug

    I will be honest about this: I am now running Codex on 2 different computers and both have the same issue - I'm LOVING codex with 5.6 sol Ultra.. but the ammount of subagents it calls for and the tasks they run... my new computer (5080 with ryzen 7 7800x3d, 32gb DDR5 6000) still needs to be restarted every 4-5 hours if I want to run Codex on ultra. I'm unclear how prevalent this bug is in codex CLI, but using Codex windows app I can guarantee it's unbearable.

    I understand this might not be affecting all users, but I'm choosing to mantain an OpenAI first envoirement - Codex windows app is vital for this. And this should be something OpenAI should strive for, allowing a user to remain in their ecosystem. Right now I paid 3k€ for a new computer and I still need stop everything and restart every 6 hours if I want to avoid going down to 0.3-0.6 fps. It makes close to 0 sense, specially the lack of replies, considering this is an issue that has been raised in multiple tickets, from multiple people.

    Yup! I wouldn't be too harsh on the Codex team, they have a gigantic backlog of 5k GitHub issues and combing through all that doesn't look like an easy task!

    I suspect that they are working on a major Codex rework or V2 - which would be a lot easier than tackling 5k issues!

  7. ArsenBilov commented on Sep 10, 2026

    @ArsenBilov

    Independent real-world observation consistent with the reported LSASS/logon-session leak

    I recorded a 37.6-hour Windows Codex Desktop + VS Code extension session and observed the same persistent whole-desktop degradation and LSASS handle accumulation described here.

    Environment:

    • Windows 11 Pro 25H2, build 26200.9168
    • Codex Desktop 26.901.6511.0
    • OpenAI VS Code extension present; it updated from 26.901.22334 to 26.903.61454 during the session
    • The newer extension binary currently reports codex-cli 0.153.4
    • Current configuration is windows.sandbox = "elevated", although the capture did not preserve the configuration file and therefore cannot prove the setting was unchanged throughout the run

    Observed LSASS handle count:

    • baseline: 3,878
    • first noticeable lag: 17,545
    • significant lag: 26,959
    • most applications lagging: 34,007
    • extremely severe lag: 40,338
    • Codex mostly unresponsive: 41,129
    • end of capture: 43,010

    LSASS gained 39,132 handles. Its thread count and private memory remained nearly flat.

    The increase was much faster during active agent work, approximately +1,500 to +1,800 handles/hour, and slowed to approximately +100 to +180 handles/hour during quieter or overnight periods.

    Codex/ChatGPT and Explorer restarted during the session, but LSASS retained the accumulated handles and the system-wide lag persisted. Only a Windows reboot returned LSASS to the normal low-thousands range and restored responsiveness.

    CPU, available RAM, disk latency, DPC/interrupt activity, and GPU utilization were all non-saturated during the worst marked lag period.

    I was not manually invoking the standalone codex sandbox command. The workload consisted of normal Codex Desktop and IDE agent activity with many command/tool executions. Therefore, this result does not prove whether the leaked resources came from the exact codex sandbox path described here, from the sandboxed codex exec path discussed in #33356, or from a shared internal implementation used by Desktop/IDE clients.

    I could not inspect Security Event 4624 for CodexSandboxOffline because Security log access was denied, and no WPR Handle trace was captured during the strongest lag. The exact leaked object type therefore remains unconfirmed.

    Could the maintainers clarify which internal sandbox entry point Desktop and IDE agent commands use, and whether it shares logon-session/token lifetime management with either codex sandbox or sandboxed codex exec?

    A privacy-reviewed timeline and aggregate handle/counter extracts are available. The complete evidence set contains 40 files and passed SHA-256 manifest verification.

  8. xPkFyre commented on Sep 14, 2026

    @xPkFyre

    Adding a kernel-level root cause for this, since the thread so far stops at the symptom (orphaned LogonType 2 sessions accumulating in lsass). We traced it into the kernel and it is an OS token-reference leak that the sandbox's token model triggers on every command.

    Environment: Windows 11 Pro 25H2, build 26200.9445. Codex Desktop 26.903.9818.0, sandbox runner 0.153.4, [windows] sandbox = "elevated".

    Root cause

    Each sandboxed command creates a fresh interactive logon (via CreateProcessWithLogonW / seclogon) for CodexSandboxOffline/CodexSandboxOnline, then builds a restricted token with restricting SIDs (CreateRestrictedToken, i.e. the NtFilterToken syscall). Inside that syscall the kernel duplicates a token and takes one reference on it that is never released. The orphaned token is then cached in the logon session's Token field, and because a live token pins its own logon session, the session's ReferenceCount can never fall to zero and it is never torn down.

    Evidence (live kernel dump)

    Pinned _SEP_LOGON_SESSION_REFERENCES for CodexSandboxOffline:

    ReferenceCount : 0n1
    Token          : 0xffffd086`29277060
    AccountName    : "CodexSandboxOffline"
    TokenList      : [ 0x0 - 0x0 ]      // empty: no live real tokens reference this session
    

    That cached token is orphaned but alive (HandleCount: 0 PointerCount: 1), and object-reference tracing on it shows one reference and zero dereferences:

    !obtrace ffffd08629277060
         80c  +1  Dflt  1  1  nt!ObCreateObjectEx+73c
                              nt!SepDuplicateToken+15d
                              nt!SepFilterToken+964
                              nt!NtFilterToken+2cc
                              nt!KiSystemServiceCopyEnd+28
    --------
    References: 1, Dereferences 0     Over reference by: 1
    

    Every frame is nt!. There is no Codex frame in the leaking path. Walking the logon session chain, this is systematic: 20-plus consecutive CodexSandbox* sessions, each with an empty TokenList but a distinct orphaned cached token (HandleCount 0, PointerCount 1, TokenFlags 0x2020) holding it alive. One leaked session plus token per command. In this dump: 24,673 sessions and roughly 125,000 lsass handles after 2.7 days of use, with lsass burning about 1 to 1.4 cores just walking the oversized session table (NTLM credential updates plus sfapm.dll opening tokens by logon id).

    It is an OS bug the sandbox pattern triggers

    We reproduced it with a minimal native executable: an interactive logon, CreateRestrictedToken with restricting SIDs, CreateProcessAsUser to launch a child, then close every handle we own. No Codex runner, IPC, job object, or private desktop. The session still leaks. Narrowing the controls: a bare interactive logon cleans up, a token-only filter (no process launch) cleans up, and a restricted token launched as a process is the case that leaks. So the trigger is the specific combination of a restricting-SID filtered token used to launch a process on an interactive logon.

    Caveat for reproducers: !obtrace only records operations by threads in the traced image, so a dereference on a system worker thread would not appear. The load-bearing evidence is not the trace count, it is the objective dump state: the token still exists with a handle count of zero and one pointer reference, and it pins a session that is one of thousands accumulated.

    Suggested fix

    The kernel over-reference is not patchable from Codex, and is worth reporting to Microsoft against SepFilterToken on this build. On the Codex side, the leak can be avoided entirely by not creating a fresh interactive logon plus a restricted token per command. Options: reuse one long-lived sandbox logon session across commands, run a persistent sandbox worker process, or confine with a job object / AppContainer that does not route through the token-filter path. Any of those converts thousands of leaked sessions into one.

  9. railapex commented on Oct 1, 2026

    @railapex

    I can reproduce the leak on demand, and I have a candidate trigger. It happens only while Windows' foreground lock is armed, meaning within ForegroundLockTimeout (default 200 s) of keyboard or mouse input. That would explain the "state-dependent" behavior reported above: the leak shows up while someone is using the machine and stops when they step away.

    Setup: same machine, same boot, same script each time. codex exec --sandbox read-only is told to make 10 shell calls, each running cmd /c "cmd /c echo …". I counted logon sessions before each batch and 20 s after it:

    Batch (local time) Time since last input Runner launches Sessions leaked
    07:32 981 s 12 0
    08:35 ~4,700 s 10 0
    10:00 1.3 s 10 6

    I paired Security events 4624 and 4634 by TargetLogonId, and the pairs agree. In the 10:00 batch, 6 of the 10 CodexSandboxOffline logons have no logoff and are still live. From 07:30 to 10:00, while nobody was at the machine, there were 147 CodexSandboxOffline logons. That count includes the two idle batches plus other Codex activity. Every one of them logged off within a few seconds.

    Earlier that morning, 77 of 83 logons had no logoff. The same command (git rev-parse HEAD) leaked on some launches and not others, so the command's content is not the trigger.

    This matches the Windows bug that bentoner traced in #30926 (write-up: https://github.com/bentoner/windows-token-leak). When a process creates a process, win32kfull!CForegroundLaunch::_CheckAllowForeground takes a reference on a primary token and never releases it, and it only reaches that code while the foreground lock is armed. My inference, not traced: that leaked reference lands on the sandbox's restricted token, and a live token keeps its logon session alive. That fits the orphaned token in the kernel dump above (HandleCount 0, PointerCount 1). That dump's !obtrace only records references taken by threads in the traced image, so a win32k reference taken on another process's thread would not show up there.

    On this box, turning the lock off confirms bentoner's token leak. With me at the keyboard, 500 processes that each start a process left 343 tokens behind at the default timeout, and 24 with ForegroundLockTimeout set to 0. An idle control left 22. Details are in #30926.

    Turning the lock off mostly stops the sandbox leak too. I ran with ForegroundLockTimeout at 0 for an evening of normal use, including stretches at the keyboard. In that time there were 275 CodexSandboxOffline logons and every one logged off, by the same 4624/4634 pairing. The one exception is a controlled batch of 10 run the moment I sat back down at the machine. It left 2 sessions behind with the lock off, against 6 of 10 with it on.

    The latest cumulative update does not fix it. After Windows Update moved the machine to build 26200.9550 (win32kfull.sys 10.0.26100.9549), with the lock back on, a Codex session this morning left 3 of 4 logons with no logoff.

    A reboot on 09-28 reset the live timeout to 2147483647, and I didn't reapply the workaround. Three days later lsass held 883 logon sessions, against 22 just after boot. I haven't paired these by event yet. On the previous boot, 1,058 of the roughly 1,100 live sessions were CodexSandboxOffline.

    What this means:

    • Codex: the one-logon-per-command design turns each of these Windows leaks into a stranded session. Reusing one sandbox logon across commands, as suggested above, would limit the damage to one session per sandbox, not one per command, whatever Windows does.
    • Users: setting ForegroundLockTimeout to 0 (per user, via SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT)) stops the token leak and nearly all of this one. The cost is that any app can then take focus. The call is refused while the lock is armed. Run it from Win+R, which works because Explorer is the foreground process, and repeat it after every logon. Check the live value, not the registry. Windows 11 sets the live value to 2147483647 at every logon regardless of the registry (OpenText documented this, and this machine does it after every reboot). At that value, any input keeps the lock armed for 24.9 days, which is why the leak looks constant during normal use.

    Environment: Windows 11 Pro 25H2, builds 26200.9278 and 26200.9550; codex-cli 0.157.0 (standalone) and 0.157.1 (npm); Codex Desktop 26.924.2738.0; [windows] sandbox = "elevated". After 16 days of uptime the machine had 1,058 live CodexSandboxOffline sessions, and lsass held 8,655 Semaphore and 1,321 Token handles.

    cc @zm-oai @iceweasel-oai, the most frequent recent committers under codex-rs/windows-sandbox-rs

  10. Tuguk commented on Oct 5, 2026

    @Tuguk

    Here's a data point from a newer build, plus two things this thread doesn't cover yet.

    Still present on Codex Desktop 26.930.3930.0, Windows 11 25H2 26200.9457, with [windows] sandbox = "elevated". The app has since updated to 26.930.4958.0 / codex-cli 0.160.0; I haven't re-measured on that version. A single echo test from the Desktop agent took LsaEnumerateLogonSessions from 16,646 to 16,647, and it was still 16,647 78 s later. By then lsass held ~104,700 handles (86,659 Semaphore, 16,780 Token) and was using ~160% of one core continuously.

    Fast Startup keeps the leak across shutdowns. Fast Startup is on by default in Windows. With it on, Shut down followed by power-on is a hybrid boot (Kernel-Boot event 27, boot type 0x1). lsass is hibernated and resumed along with every orphaned session. This machine was shut down every day, so its owner believed it had been rebooted. The last full boot (0x0) was actually 19 days earlier, which is how it reached 16.6k sessions. Only Restart clears the sessions, or Shut down once Fast Startup is turned off. Workaround advice that says "reboot" should say Restart.

    Symptom: 3–4 s hangs on paste. The first visible symptom here wasn't window lag. It was intermittent 3–4 s freezes on Ctrl+V in Chrome, Firefox (Google Sheets, Excel Online) and Notepad when copying between apps; Notepad→Notepad was fine. During a freeze the window still answered WM_NULL, and no process held the clipboard open. A Restart fixed it immediately: 10 sessions, 2,156 lsass handles, 0% CPU. I inferred the link from lsass to paste; I didn't trace it. I'm posting it so people searching for "paste lag" can find this issue.

  11. talraveh1 commented on Oct 8, 2026

    @talraveh1

    Data point on the newest CLI and a newer Windows branch: codex exec still leaks on codex-cli 0.160.0 (npm) and Windows 11 Pro 26H2, build 26300.9457. Every build reported above is 26200.x. It is the same pattern @railapex measured on 0.157: most sandboxed commands leave a CodexSandboxOffline logon session behind.

    Run: one codex exec with [windows] sandbox = "elevated" and the default read-only sandbox, told to make 10 separate shell calls that run whoami. Each ran as CodexSandboxOffline. 2026-10-08, 14:40:31 to 14:41:19 local time, with the machine in interactive use.

    Security events 4624 paired with 4634/4647 by TargetLogonId (script below):

    Window CodexSandboxOffline logons (type 2, seclogo) Logged off No logoff, still a live session
    The run (48 s) 10 3 7 (checked 70 min later)
    Since boot (10 h, all Codex use on this machine) 234 99 135

    Win32_LogonSession went from 133 to 140 across the run and was still 140 two minutes later.

    Kernel tokens: the live count of pool tag Toke rose by about 140 during the run and was back to its pre-run level (16,469) seven minutes after the run ended. So a stranded session pins very few token objects, consistent with the single cached token per session in @xPkFyre's dump. The cost is the session and lsass growth, not token pool.

    Foreground lock: the live ForegroundLockTimeout here is 2147483647 while HKCU\Control Panel\Desktop holds 200000, so the logon-time override described above also happens on 26H2, and the lock was armed for the whole run. I did not change it, so this is not an A/B test of that trigger.

    Codex Desktop 26.1002.6548.0 is also installed (its codex-windows-sandbox-service.exe runs as SYSTEM). The run above used the CLI only.

    Pairing script (elevated PowerShell; needs Logon and Logoff success auditing)
    # Pairs Security events 4624 (logon) with 4634/4647 (logoff) for the Codex sandbox accounts, by TargetLogonId,
    # logged on in the window, with logoffs up to now, and checks which logon ids are still live sessions. Needs an elevated shell and logon/logoff auditing.
    param([datetime]$From = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime, [datetime]$To = (Get-Date))
    $users = "(Data[@Name='TargetUserName']='CodexSandboxOffline' or Data[@Name='TargetUserName']='CodexSandboxOnline')"
    function Ev($ids, $until) {
      $x = "*[System[($ids)]] and *[EventData[$users]]"
      Get-WinEvent -LogName Security -FilterXPath $x -EA 0 | ? { $_.TimeCreated -ge $From -and $_.TimeCreated -le $until } | % {
        $d = @{}; ([xml]$_.ToXml()).Event.EventData.Data | % { $d[$_.Name] = $_.'#text' }
        [pscustomobject]@{ Time = $_.TimeCreated; Id = $_.Id; User = $d.TargetUserName; LogonId = [Convert]::ToUInt64($d.TargetLogonId, 16)
                           Type = $d.LogonType; Process = $d.LogonProcessName } } }
    $on = @(Ev 'EventID=4624' $To); $off = @(Ev 'EventID=4634 or EventID=4647' (Get-Date))   # logoffs up to now
    $offIds = @{}; $off | % { $offIds[$_.LogonId] = $_.Time }
    $live = @{}; Get-CimInstance Win32_LogonSession | % { $live[[uint64]$_.LogonId] = $true }
    "window {0:HH:mm:ss} - {1:HH:mm:ss}" -f $From, $To
    $on | group User | % { $g = $_.Group
      $noOff = @($g | ? { -not $offIds.ContainsKey($_.LogonId) })
      "{0}: {1} logons (type {2}, via {3}); {4} logged off; {5} with no logoff, of which {6} are still live sessions" -f $_.Name, $g.Count,
        (($g.Type | sort -Unique) -join '/'), (($g.Process | % { "$_".Trim() } | sort -Unique) -join '/'), ($g.Count - $noOff.Count), $noOff.Count,
        @($noOff | ? { $live.ContainsKey($_.LogonId) }).Count }
    "live sessions now: {0}" -f $live.Count

    With no arguments it covers everything since boot; -From '2026-10-08 14:40:31' -To '2026-10-08 14:41:19' gives one window.

  12. xlookum commented on Oct 15, 2026

    @xlookum

    Still reproducing on the newest build I can find:

    • Codex Desktop 26.1007.2314.0, codex-cli / command-runner 0.162.0-alpha.17.2
    • Windows 11 Pro 25H2, build 26200.9457, [windows] sandbox = "elevated"
    • Normal interactive use of the Desktop app (agent + computer use), no scripted load

    After 9.2 days of uptime:

    Metric Value
    Live CodexSandboxOffline logon sessions (Win32_LoggedOnUser) 27,888
    CodexSandboxOffline type-2 logons (4624, seclogo) today 1,729 (~1/min)
    Matching logoffs (4634/4647) today 129
    lsass handle count 141,956
    Token handles held by lsass itself (system handle table, type Token) 28,080

    No Codex process holds a meaningful share of the token handles (largest is ~700 handles total), so closing the app does not release anything — consistent with the kernel/lsass-side analysis above.

    Possibly new: csrss.exe for session 1 is at 11.1 GB private bytes (working set ~10 MB, so it's almost entirely paged-out commit). That's ~418 KB per leaked session. csrss is flat while I watch it (no growth over 5 sandbox logons in 3 minutes), so it seems to grow in steps rather than per command — I'm treating this as correlation, not proof, but nobody in this thread has mentioned csrss yet and it's 11 GB of commit charge on a 64 GB machine. Has anyone else checked csrss (session 1) private bytes on an affected machine?

    Practical impact here: total commit hit ~110 GB on 63 GB RAM, which pushed everything else into the pagefile and caused system-wide stutter.

  13. BIOcanse commented on Oct 27, 2026

    @BIOcanse

    Another data point from a heavily automated Windows setup.

    Environment

    • Windows 11 Home, build 26300
    • The Codex Desktop app runs continuously (ChatGPT desktop 156.0.8078.48).
    • Automated headless use calls the bundled codex exec directly with -c sandbox_mode="workspace-write". Several runs are usually in parallel, and each run executes many sandboxed commands.
    • codex-command-runner 0.164.0-alpha.11.1

    Observation (about 47 h after boot)

    04:29 local 04:57 local
    CodexSandboxOffline interactive logon sessions (Win32_LogonSession grouped by account) 4,789 5,300

    That is +511 in 28 minutes, about 1,100 per hour under this load. Sessions are never released before reboot.

    Other figures:

    • lsass.exe: 28,597 handles at the second sample, including about 20,100 semaphore handles, roughly 4 per leaked session.
    • Kernel paged pool Toke: 198 MiB.

    This matches #35940 and #33356. Both the Desktop app and the codex exec runs use the same sandbox account on this machine, so I cannot say how many sessions each one contributes. The growth rate does track the automated codex exec workload.

    I can provide a timeline of session count against command count if that helps.

  14. lorthris commented on Oct 31, 2026

    @lorthris

    Still present on the newest builds, plus a measurement of what each leaked session costs in kernel memory. As far as I can see, nobody in this thread has posted that cost yet.

    Environment

    • Windows 11 Enterprise 26H2, build 26300.9711. Fast Startup is off (HiberbootEnabled = 0), so the counts below cover a real 11 days of uptime.
    • Codex Desktop 26.1023.6621.0, app-server codex-cli 0.164.0-alpha.11.1, standalone codex-cli 0.165.0
    • [windows] sandbox = "elevated". Normal interactive use of the Desktop app, plus headless codex exec calls.

    Session count (2026-10-31, booted 2026-10-20)

    Metric Value
    Live CodexSandboxOffline logon sessions (Win32_LoggedOnUser) 13,562
    Any other account's sessions 9
    New type-2 NTLM sessions per hour during active use 649–766
    lsass handles 69,604

    Kernel pool cost (NtQuerySystemInformation(SystemPoolTagInformation))

    Tag Paged pool Outstanding allocations
    Toke 3,480 MB 1,679,211
    SeAt 628 MB 6,802,561
    SeTd 225 MB 1,679,211
    SeDt 126 MB (+39 MB nonpaged) 1,642,167

    That is about 4.5 GB of paged pool, and total paged pool is 8.9 GB. Commit charge is 29.2 of 31.9 GB, so on a 24 GB machine this is now pushing toward commit exhaustion, not just slowing things down.

    What I think this adds:

    • About 124 token objects stay alive per leaked logon session (1.68 M Toke allocations ÷ 13.5 k sessions), and only about 55 k Token handles exist system-wide. So most of the leaked tokens are held by kernel references, not handles. That fits @xPkFyre's NtFilterToken token-reference analysis, and it suggests every derived or filtered token pins the session, not only the logon token.
    • Toke and SeTd have identical allocation counts, and SeDt is close to them. That is consistent with whole token objects leaking, rather than just their dynamic parts.
    • Each leaked session costs about 330 KB of paged pool. At the rate above, that is about 230 MB an hour during active use, which matches the 4–5 hour restart interval other people here have reported on 32 GB machines.

    This is the top resource drain on the machine, and the only remedy is a reboot every few days. Could a maintainer acknowledge it and say whether a fix is planned? Even an interim mitigation would help, such as reusing one logon session per runner instead of a fresh CreateProcessWithLogonW per command, or explicitly closing the derived restricted tokens. I can run a debug build or collect more counters (for example ETW or !logonsession output) if that would help.

  15. HK1211 commented on Nov 13, 2026

    @HK1211

    Reproduced on codex-cli 0.167.0 after a clean restart — logon session persisted for at least 15 minutes

    Environment. Windows 11 Pro 25H2 (26200.9711). The runs below used codex-cli 0.167.0 (npm) with [windows] sandbox = "elevated". Codex Desktop 26.1103.4239.0 and its sandbox service were also running. Third-party security software with kernel-mode components is installed (AhnLab V3 Lite / Safe Transaction). We did not test without it.

    Clean-restart pair (one run each, no model call)

    R1 R1b
    Launched boot + 10 min boot + 15 min
    Command codex sandbox -- cmd /c exit 0 codex sandbox -- powershell -NoProfile -Command "git --version"
    Logon sessions (LsaEnumerateLogonSessions) 15 → 15, monitored to +3 min 15 → 16; the new LUID was still present at about +15 min
    Security log (4624 / 4634 paired by TargetLogonId) logon and logoff within the same second CodexSandboxOffline, type 2, seclogo. Its LogonId equals the new LUID. No 4634 when queried at about +9 min

    So a fresh boot was not enough to prevent the leak here. Earlier in this thread, 8 runs on a fresh boot leaked none.

    The cmd /c exit 0 run was released this time, although the original report saw that command leak. That fits the intermittent per-launch behaviour @railapex reported, where the same command leaked on some launches and not others. With one run each, we did not measure a leak rate, and we cannot say what differed between R1 and R1b.

    We read ForegroundLockTimeout only from the registry (200000). We did not read the live value, so these runs cannot be placed relative to the foreground-lock trigger.

    Before that restart (6 d 8 h uptime, about 4 days of heavy automated multi-agent use)

    • The sandbox log (.sandbox/sandbox.YYYY-MM-DD.log) has 14,453 START: lines since boot: PowerShell 7,894, --codex-run-as-fs-helper 6,544, other 15.
    • LsaEnumerateLogonSessions returned 12,523 logon sessions. The interactive user could read details for only 2 of them.
    • The Security log (20 MB, circular) had already overwritten those days, so we could not pair 4624/4634 events for them. Instead, we estimated each session's creation time without admin rights.
      • Logon-session LUIDs and token IDs come from the same increasing counter. We paired running processes' start times with their primary TokenIds (338 points) to map LUID to time.
      • Hour by hour over 65 hours, estimated session creations track START: lines: Pearson r = 0.77, Spearman ρ = 0.70.
      • Several hours match exactly, including hours dominated by fs-helper launches. For example, one hour had 195 sessions against 195 launches: 45 PowerShell and 150 fs-helper.
      • Over the whole period, sessions ÷ launches = 0.87. This is a ratio of totals. It is not a per-launch leak probability, because sessions were not matched to individual launches.
      • In about 54 h after sandbox activity stopped, only 3 new sessions appeared.
    • lsass held 51,165 Semaphore and 12,654 Token handles, the same ~4:1 and ~1:1 per-session ratios reported above.
    • Paged-pool Toke allocations were about 2.47 M (5.1 GB). We do not attribute that figure to the stranded sessions: it kept rising by about 80/min while no sandbox commands ran. This is in line with @talraveh1's note that stranded sessions pin few token objects.
    • After a Restart: 15 sessions, lsass 1.9 k handles, paged pool 2.0 GB.

    Not established by this data: the trigger condition, the leak rate, what pins the session, and the cause of the user-visible slowdown on this machine. Other kernel-resource anomalies were present at the same time.

    Question. The thread has suggested reusing one sandbox logon per runner or per session, rather than one per command. Is that viable for elevated mode? We can provide additional diagnostic data, or run a targeted reproduction, if maintainers identify a specific measurement that would help.

  16. NicolasDLT commented on Nov 14, 2026

    @NicolasDLT

    Another data point, with a measurement this thread doesn't have yet: what the leak does to process-creation latency for everything else on the machine.

    Environment. Windows 11 Pro 25H2 (26200). Codex Desktop 26.1111.2228.0, bundled codex-cli 0.167.0-alpha.3.2. Heavy automated use: up to 8 parallel codex exec tasks in workspace-write, each running tests and git, plus read-only review runs.

    lsass handles.

    Moment lsass handles
    ~1.5 days after the previous boot, heavy use ~83,000 (+~40 per 30 s even with only 2 tasks running)
    Right after a real restart ~1,900–2,100
    +2 h of normal workload after the restart 6,494

    Sampling every 30 s after the restart and grouping by 10-minute windows, growth tracked the number of concurrent codex exec write tasks almost exactly: +1 with one read-only review, +43/+79 with no Codex task, +254/+487 with one write task, +1,070/+1,353 with 3–5 write tasks. A batch of 71 Python/git tests (no Codex) spawning thousands of processes moved lsass from 1,846 to 1,808 (no growth). A single read-only review over 7 minutes: ~1,900 → ~1,970.

    Effect on everything else (the part that made it hard to attribute). Our CI-like validation spawns ~45,000 short processes (git, python, cargo). It records the median and p90 time of 20 git --version / python -c pass spawns at start:

    git spawn median / p90 python spawn median validation wall time
    Healthy (fresh boot) 0.02 s / 0.02 s 0.03 s 7–9 min
    Same workload, lsass in the tens of thousands 0.26 s / 0.92 s 0.25 s 56 min

    The test count barely changed between those runs (+27% Python tests, same Rust tests, +15% spawned processes), and the Rust test phase (identical test count) went from 6 to 47 minutes. So the leak slows down every CreateProcess on the machine, not just desktop responsiveness: any build or test runner that spawns many processes degrades over the day and recovers only after a restart. As noted above, a shutdown with Fast Startup is not enough.

  17. mcmorry commented on Nov 16, 2026

    @mcmorry

    Data point that adds the kernel stack behind the process-creation slowdown NicolasDLT measured above.

    Environment. Windows 11 Pro 25H2 (26200), Codex Desktop 26.1106.6628.0, codex-cli 0.167.0, [windows] sandbox = "elevated", Fast Startup on.

    Where the launch time goes. An elevated WPR trace of a probe that times 300 CreateProcess calls, alternating cmd /d /c exit and git --version, on a machine with about 6 days of uptime. All 8 launches over 198 ms were held inside nt!SepCleanupMarkedForDeletionEntries, the kernel's security-token index maintenance, during process creation. Three charged about 230–250 ms of CPU to the calling thread in that cleanup, and five waited about 200–233 ms on the same kernel lock. Image file opens took microseconds, and Defender and other file-system filters were not in the slow stacks. This is consistent with the stranded sessions and tokens slowing every process launch on the machine, not only lsass, though the trace alone does not prove the link.

    Growth with uptime. The same 300-launch probe every 6 hours after a Restart. The slowest launch grew steadily: 5 ms at boot + 16 min, then 23, 26, 27, 41, 45, 50, 54, 56, 54, 67, 73 and 92 ms at boot + 3 days. Six hours later it was 248 ms, with 29 of the 300 launches over 100 ms. At 78 h of uptime LsaEnumerateLogonSessions returned 414 sessions, and only 2 of them were interactive. Five codex sandbox -- cmd /c exit runs raised the count by 5, and it stayed there.

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

    CLIbugperformancesandboxwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions