gh auth returns invalid token in sandbox
Open 💬 2 comments Opened Aug 6, 2026 by lambegraham
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
What version of Codex CLI is running?
latest
What subscription do you have?
Pro
Which model were you using?
5.6 Terra
What platform is your computer?
Darwin 25.5.0 arm64 arm
What terminal emulator and version are you using (if applicable)?
_No response_
Codex doctor report
What issue are you seeing?
gh auth status reports the active GitHub token as invalid, then API calls fail with error connecting to api.github.com. This prevents repository creation and other GitHub CLI actions from within the sandbox.
Token is confirmed as valid.
What steps can reproduce the bug?
- Open Codex Desktop with an existing
ghlogin. - Run GitHub CLI commands through the sandboxed terminal:
gh auth status
gh api user --jq .login
- Observe that
ghreports the active token as invalid and cannot connect toapi.github.com.
Observed output:
github.com
X Failed to log in to github.com account lambegraham (default)
- Active account: true
- The token in default is invalid.
error connecting to api.github.com
What is the expected behavior?
Sandboxed gh commands should either:
- access the existing GitHub authentication and reach
api.github.com; or - clearly state that sandboxing blocks Keychain/network access, rather than reporting the token itself as invalid.
Additional information
- Codex CLI version:
0.142.5 - The error mixes an apparent authentication failure with a network-connection failure, so it is unclear whether the sandbox cannot access the GitHub token, cannot reach GitHub, or both.
- As a workaround, GitHub CLI commands must be run outside the sandbox.
2 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Running into a similar issue myself.
Codex's "Approve for me" mode requires explicit escalation for
ghcommands; that's fine, but agents are never instructed to escalate on failed attempts, so they mistakenly report a stale CLI token.