How can I run vscode with sudo on osx?

The following should do it:

sudo /Applications/Visual Studio Code.app/Contents/MacOS/Electron

In case of a default installation (e.g.: under default applications folder)

Try running

sudo open /Applications/Visual\ Studio\ Code.app

After you make a save on a protected file it will ask you, then just hit overwrite it will prompt for your sudo password.

if you are not sure about the location of you VSCode app, just drag and drop the icon from where it is to the terminal, it will print the path automatically after the dragging, after that just exec sudo open command and append the path, in my case was the one above, hope this helps!