When trying to run commands as sudo, I get an error

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.

I am not running any containers and sudo works fine in the default terminal.

I found this page but there are no instructions as to how this flag can be unset: https://manpages.ubuntu.com/manpages/jammy/en/man8/sudo.8.html

  • 1
    did you install vscode as snap? The problem is that vscode is prevented from escalating privileges, so you have to start vscode in a way that allows privilege escalation (or just use the regular terminal for this)
    – Esther
    Commented Sep 21, 2022 at 17:25
  • Hi @Esther Thanks for the hint, but it's installed through apt and not snap.
    – Siamore
    Commented Sep 22, 2022 at 13:44
  • 1
    you can try adding the --no-sandbox flag when running vscode from terminal, see if that changes anything. Although realize that makes things less safe, since bugs and such in vscode can now possibly escalate privileges until they can affect your system.
    – Esther
    Commented Sep 22, 2022 at 13:45
  • Hi @Esther, Thanks that works! I did need to quit all instances first for it to take effect. unfortunately this indicates that the limitation is by design and I'll take your advice and use a regular terminal for things that need sudo. Would you want to make this into an answer that I can accept so that it's more accessible for others who might have a similar issue?
    – Siamore
    Commented Sep 22, 2022 at 13:53

3 Answers 3


The issue here is that VS Code sandboxes itself in order to prevent bugs (or malicious extensions/etc) from being able to escalate privileges and potentially harm your system. Therefore, any process it starts, including sudo in the terminal, is prevented from starting as PID 0 and becoming root.

You can start vscode with the flag --no-sandbox to disable this sandbox. This will allow processes started by vscode to run as root, and will allow you to use sudo in the vscode terminal. However, this does leave your system somewhat more vulnerable, as the inability to run processes as root is a deliberate design decision made for security purposes.


I just needed to run a sudo chown ... command and I simply opened a regular terminal and ran it. I know this is not the good answer but if you are in a hurry and just want to run a command and proceed with VSCode terminal, consider it.


So, you have to do a couple things. First, make sure your user is in the docker group.
Second, find the process that you have for your vscode server with a ps aux | grep 'bin/code-server' | grep -v grep | awk '{print $2}.
Third, kill that process with kill .
Then restart your vscode session and you should be good!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .