Skip to content

Codex on Windows records nothing: its sandbox user cannot read the API token or write the spool #302

Closed

Description

@blitzcrieg1

Summary

With Codex's default Windows sandbox ([windows] sandbox = "elevated"), Codex runs hooks as its sandbox account (codexsandboxoffline). That account can run the hook script and reach the recorder on loopback, but it cannot read the API token, which Agentmetry restricts to the installing user. Every Codex event is posted without a key, refused with 401, cannot be spooled because the sandbox account cannot write to the data directory, and is lost. Nothing reports it. Coverage still says Codex is hooked.

Evidence (run inside Codex's own sandbox with codex sandbox -- ..., Codex CLI 0.163)

Check as the sandbox user Result
whoami <host>\codexsandboxoffline
Read scripts/agentmetry_ingest.py allowed
Read apps/orchestrator/.env allowed
GET /api/v1/health on 127.0.0.1:8000 200
Read the API token file denied
Write to the data directory (spool) denied
POST /api/v1/audit/ingest without a key 401

Codex's own log shows every hook as started and completed; the trail received zero Codex events over a week of Codex use.

Why the obvious workarounds are wrong

Granting the sandbox account read on the full API token, or putting the token in Codex's hook config, hands a sandboxed and possibly prompt-injected agent a key that can read the trail and close detections.

Fix

  1. The core mints an ingest-only token (ingest-token, which hooks already prefer) and accepts it on POST /api/v1/audit/ingest only. Every other route keeps requiring the full key.
  2. hooks install for Codex on Windows grants read on that token to Codex's sandbox accounts when they exist.
  3. doctor fails when Codex's sandbox accounts exist and cannot read an ingest token, instead of reporting Codex as covered.
  4. Follow-up: a spool location the sandbox account can write, so events survive a recorder restart.

Related: #300.

Activity

  1. blitzcrieg1 commented on Oct 21, 2026

    @blitzcrieg1
    OwnerAuthor

    Verified after #303 merged, inside Codex's real sandbox (codex sandbox -- ..., Codex 0.163):

    • The sandbox account reads the ingest-only token and still cannot read the full API token.
    • The real Agentmetry hook runs as that account and attempts the POST; doctor reports [OK] Codex's sandbox accounts can send events with the ingest-only token.
    • hooks install granting the two sandbox accounts read is sufficient; no group entry is needed.

    Two follow-ups found on the way:

    1. The trail file itself is readable by the sandbox. Codex grants its sandbox group read on folders opened as Codex workspaces. When the Agentmetry data directory sits inside such a folder (a source checkout's apps/orchestrator/data), a sandboxed agent can read the trail, including command text where command logging is on. Any agent running as the user could already read it, so this is not new exposure, but doctor could warn when the data directory is inside a Codex workspace, and the docs should recommend a data directory outside source checkouts.
    2. Testing note: quoted paths passed through codex sandbox -- cmd /c "..." arrive mangled and read as access denied. An earlier round of checks here produced false denials that way; every result above was re-run with unquoted paths and direct invocation.
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions