codex gets stuck at sudo step running on Ubuntu

Open 💬 6 comments Opened Nov 2, 2025 by nv186000
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.53.0

What subscription do you have?

Pro

Which model were you using?

gpt 5 codex

What platform is your computer?

Linux 6.8.0-59-generic x86_64 x86_64

What issue are you seeing?

When Codex executes a command requiring sudo privileges, the terminal enters a password prompt state where user keyboard input does not register properly. The prompt appears, but input is either partially displayed or not accepted at all. The session becomes unresponsive to normal keyboard input.

Observed Behavior

Codex runs a command that triggers sudo

Terminal displays password for <user>: prompt

User attempts to type password

Input is not accepted (random characters appear or nothing appears)

Terminal becomes effectively frozen

Pressing Esc repeatedly sometimes restores control, but often fails even if it restore control keyboard input is only taken in partially

In many cases only Ctrl+C works, and sometimes the entire session must be closed

After force-closing, user must run codex resume to continue

it is not clear whether codex is actually working or it is waiting for a password . even if it is waiting for a password we cannot provide it as inout does not work

<img width="2037" height="432" alt="Image" src="https://github.com/user-attachments/assets/e6a941a3-2cbc-4ee2-b7a7-bd566cf34480" />
<img width="1357" height="222" alt="Image" src="https://github.com/user-attachments/assets/29b8a7da-d0c5-453b-876e-2d3c54dcd2bc" />
<img width="876" height="152" alt="Image" src="https://github.com/user-attachments/assets/1fb793e8-7f9d-45c3-88bc-7957ca794ba2" />

What steps can reproduce the bug?

Start a Codex CLI session on Ubuntu

Let it do some trivial stuff

Then let cidex do something that needs a sudo privilege like sudo docker ( does not really matter as long as sudo is involved)

Terminal shows password prompt

User tries to type password

Terminal freezes / does not accept input

Press Escape many times some times it work sometime it does not , if it works try to type anything and whatever you input will not appear on screen fully

What is the expected behavior?

Password input should be accepted normally, or

Codex should detect interactive sudo context and:

Prompt user for password securely, or

Fall back to non-interactive mode with proper guidance

Additional information

_No response_

View original on GitHub ↗

6 Comments

github-actions[bot] contributor · 9 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #5349

Powered by Codex Action

tfriedel · 9 months ago

I also observed this issue. Very annoying!
I also don't understand why it should get sudo permissions at all.
If I manually run sudo before, programs will not ask for sudo password for some time. I though this could be a workaround.
But then I see this:

  └ sudo: The "no new privileges" flag is set, which prevents sudo from running as root.
    sudo: If sudo is running in a container, you may need to adjust the container configuration to disable the flag.

Seems like it's running in some container as root?

InfinityZ25 · 6 months ago

just ran into this in ubuntu, really annoying

sstklen · 6 months ago

Hey! I ran into a similar pattern in our bug knowledge base and thought this might help.

What's happening: Codex sandbox sets PR_SET_NO_NEW_PRIVS (prctl/seccomp) which kernel-blocks sudo privilege escalation. Additionally, Codex PTY layer does not properly relay interactive stdin to sudo password prompt, causing frozen terminal.

What worked for us:

Pre-scan commands for sudo/pkexec before execution. If detected: (1) reject with clear error explaining sandbox limitation, (2) suggest user run sudo -v in a separate terminal to cache credentials (won't work due to no_new_privs), or (3) recommend user pre-install dependencies outside Codex. For the frozen terminal: add a timeout on interactive stdin prompts and detect sudo password prompt pattern to abort early with actionable message.

// In command executor, before spawning process:
const PRIVILEGE_ESCALATION = /\b(sudo|pkexec|doas|su\s)\b/;
if (PRIVILEGE_ESCALATION.test(command)) {
  return {
    error: 'SANDBOX_NO_SUDO',
    message: 'Commands requiring sudo cannot run inside Codex sandbox (no_new_privs is set). Run this command manually in your terminal, then retry without sudo.'
  };
}

// In PTY output handler, detect stuck sudo prompt:
const SUDO_PROMPT = /\[sudo\] password|Password for/;
if (SUDO_PROMPT.test(output)) {
  process.kill(childPid, 'SIGTERM');
  return { error: 'SUDO_PROMPT_DETECTED', message: 'sudo password prompt detected — aborting. Run privileged commands outside Codex.' };
}

Hope this helps! Let me know if it doesn't match your case — happy to dig deeper. 🦞

_Disclosure: This analysis is from Confucius Debug, an AI-powered community KB for agent bugs. Please verify before applying._

---
<sub>🦞 Confucius Debug — community knowledge base for AI agent bugs. Free to search via MCP.</sub>

SuperJMN · 5 months ago

It's happening to me. Whenever I want codex run some "sudo" command, it doesn't allow me to type the password, so it's always stuck on some tasks, like debugging driver problems.

xyehya · 4 months ago

A workaround for linux users:

Run sudo visudo to edit the sudoers file
Add a line for your user:
your_username_here ALL=(ALL) NOPASSWD: ALL

Note: This has significant security implications and should ideally be restricted to specific commands like
NOPASSWD: /usr/bin/apt-get)