sudo: The "no new privileges" flag is set, in Claude Code or Codex
Why sudo fails inside Claude Code's or Codex's sandbox on Linux, how to find which process set the flag, and the legitimate ways to run the root step.
The message is sudo’s own, and it means the command ran inside your coding agent’s sandbox. On Linux, Claude Code’s sandbox and Codex’s both run commands under bubblewrap, which sets the kernel’s no_new_privs flag on everything it starts. With that flag the kernel ignores sudo’s setuid bit, so sudo cannot become root, and it stops. The flag is inherited by every child process and cannot be switched off, so nothing typed in that shell will clear it. Run the step that needs root yourself, in your own SSH session, and let the agent carry on from there. If the agent has to run it, that is a change to how the agent is allowed to run commands, made in its own settings, not in sudo.
The full message, and what triggers it
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.CopiedIn sudo’s source this is a Linux-only check: when sudo starts and finds it is not running as root, it asks the kernel whether no_new_privs is set for its own process and, if it is, prints these two lines and exits. Changing the sudoers file or the password does not help, because the kernel has already declined to make sudo root.
The flag is a Linux process attribute. The kernel documentation says that once it is set, “the setuid and setgid bits will no longer change the uid or gid”, and that “it is inherited across fork, clone, and execve and cannot be unset.” sudo is a setuid program, so it is exactly what the flag disarms. Sandboxes set it, among other reasons because the kernel only lets an unprivileged process install a seccomp filter once the flag is on. The second line’s talk of containers is sudo’s guess; on a server running an agent, the “container” is usually the agent’s sandbox.
Check where the flag comes from
The kernel reports the flag for every process in /proc/<pid>/status. Ask the agent to run this, then run it yourself in a fresh SSH login:
grep -E 'NoNewPrivs|Seccomp' /proc/self/statusCopiedNoNewPrivs: 1 inside the agent and 0 in your own login means the agent, or something that started it, set the flag. If your own login shows 1 as well, the flag comes from further out: a container, a service unit, or the terminal you are typing in. To find the process that set it, walk up the parent chain and look for the first 1 above a 0:
pid=$$ # or the process ID of the agent
while [ "$pid" -gt 1 ]; do
printf '%s %s ' "$pid" "$(ps -o comm= -p "$pid")"
grep NoNewPrivs "/proc/$pid/status"
pid=$(ps -o ppid= -p "$pid" | tr -d ' ')
doneCopiedInside a sandbox the walk may stop short of the real parents. Run it as yourself, starting from the agent’s process ID, to see the whole chain.
Claude Code
Claude Code’s sandbox is off by default and, once turned on with /sandbox or sandbox.enabled, runs each Bash command under bubblewrap on Linux and WSL2. A command that starts with sudo stays in it whatever you list. The settings reference for sandbox.excludedCommands says “Claude Code keeps a Bash call sandboxed when it has one of these shapes, among others: A command starting with sudo, eval, or xargs.” So an entry such as "sudo docker ps" does not help: a reporter in anthropics/claude-code#109604 (version 2.1.323, November 2026) tried exactly that, then closed the issue as documented behaviour.
The legitimate routes are to run the root step yourself, or to turn the sandbox off for the work that needs root and accept what that removes. With the sandbox off, Claude Code does not start commands under bubblewrap, so this flag no longer comes from Claude Code; whether sudo then lets the agent in is decided by your sudoers rules.
The Claude desktop app on Linux is a separate case. In #100854 and #102029, users report the whole app running with the flag, so sudo fails even in the app’s own Terminal panel. Commenters on the open report say it appears after the app relaunches itself, after an update or a crash, and that quitting and starting it again from the launcher clears it. These are user reports, not a statement from Anthropic.
Codex
Codex’s read-only and workspace-write modes run commands in its sandbox, and per OpenAI’s documentation “Linux uses bwrap plus seccomp by default.” In the sandbox source at 0.170.0, the code that sets the flag carries the comment that it “is required for seccomp, but it also prevents setuid privilege elevation.” In those modes, then, sudo inside a command fails with this message. Problems with bubblewrap itself, such as a missing bwrap or blocked user namespaces, are covered in Codex’s bubblewrap errors.
The documented ways for a command to run outside the sandbox are approval, where Codex asks before going beyond the sandbox’s boundary, and full access: --sandbox danger-full-access, where the agent “runs without sandbox restrictions”, or --dangerously-bypass-approvals-and-sandbox (alias --yolo), which OpenAI’s table describes as “No sandbox; no approvals” and marks not recommended. Users have reported both falling short, with no maintainer reply as of November 19, 2026:
- #33349 (open): with any filesystem deny rule in the permission profile, an approved command stays in the sandbox. #34059, closed as its duplicate, shows the sudo message after approving a command on a remote host over SSH.
- #48908 (open, 0.157.1 on Fedora CoreOS): the flag still set under
--yolo. A reply there suggests checking whether the command’s parent iscodex-linux-sandboxorbwrap(the sandbox is still in the path) orcodexitself (the flag came from outside Codex); the parent walk above shows which. - #44680 (open): the Codex desktop app on Linux carrying the flag after it relaunches itself; a commenter reports that quitting and reopening it restores sudo.
When the agent is not the cause
- A systemd service.
NoNewPrivileges=yesin the unit, per systemd.exec, “ensures that the service process and all its children can never gain new privileges throughexecve()”, andDynamicUser=turns it on too. An agent started as a service, as in keeping an agent running as a user service, inherits whatever its unit sets, so look for either line in the unit file. - A Docker container. Started with
--security-opt no-new-privileges, which the Docker reference says means “commands that raise privileges such assuorsudono longer work.” Here sudo’s container hint is literally right.
In both cases the setting was chosen by whoever wrote the unit or the container command. Removing it lets every process inside use sudo and other setuid programs again, which is what it was put there to stop.
What not to do
There is no command that clears the flag from inside the process that has it; the kernel guarantees that. Running the agent as root to get past it trades a failed command for an agent that holds the whole machine. The safer setup is the one in securing a VPS for Claude Code and Codex: the agent’s user has no sudo at all, and the few steps that need root, installing a package or editing a system file, are yours. Have the agent print the command it wanted to run instead of running it, read it, and run it in your own session.