12

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

Siamore
  • 864

3 Answers3

14

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.

Esther
  • 3,932
0

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.

0

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!

storm
  • 5,013