# @vscode/sudo-prompt

> Run a command using sudo, prompting the user with an OS dialog if necessary

Latest version **9.3.2** (published 2026-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @vscode/sudo-prompt
pnpm add @vscode/sudo-prompt
yarn add @vscode/sudo-prompt
bun add @vscode/sudo-prompt
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 9.3.2 |
| Published | 2026-01-08 |
| First published | 2021-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 43.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Joran Dirk Greef |
| Maintainers | kaimaetzel, lszomoru, alexandrudima, sbatten, joaomoreno.ms, microsoft1es, rebornix, vscode-bot |
| Keywords | sudo, os, dialog, prompt, command, exec, user access control, UAC, privileges, administrative, elevate, run as administrator |

## Links

- npm: https://www.npmjs.com/package/@vscode/sudo-prompt
- Repository: https://github.com/microsoft/vscode-sudo-prompt
- Homepage: https://github.com/microsoft/vscode-sudo-prompt#readme
- Issues: https://github.com/microsoft/vscode-sudo-prompt/issues
- npm.io page: https://npm.io/package/@vscode/sudo-prompt

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 9.3.2 (latest) — 2026-01-08
- 9.3.1 — 2021-11-19
- 9.3.0 — 2021-11-17

## README

# sudo-prompt

Run a non-graphical terminal command using `sudo`, prompting the user with a graphical OS dialog if necessary. Useful for background Node.js applications or native Electron apps that need `sudo`.

**Note:** the origin of this work is at https://github.com/jorangreef/sudo-prompt and has been moved to https://github.com/microsoft/vscode-sudo-prompt for maintenance and use in VS Code as that original repository is archived by now.

## Cross-Platform
`sudo-prompt` provides a native OS dialog prompt on **macOS**, **Linux** and **Windows**.

![macOS](https://raw.githubusercontent.com/jorangreef/sudo-prompt/master/macos.png)

![Linux](https://raw.githubusercontent.com/jorangreef/sudo-prompt/master/linux.png)

![Windows](https://raw.githubusercontent.com/jorangreef/sudo-prompt/master/windows.png)

## Installation
`sudo-prompt` has no external dependencies and does not require any native bindings.
```
npm install sudo-prompt
```

## Usage
Note: Your command should not start with the `sudo` prefix.
```javascript
var sudo = require('@vscode/sudo-prompt');
var options = {
  name: 'Electron',
  icns: '/Applications/Electron.app/Contents/Resources/Electron.icns', // (optional)
};
sudo.exec('echo hello', options,
  function(error, stdout, stderr) {
    if (error) throw error;
    console.log('stdout: ' + stdout);
  }
);
```

`sudo-prompt` will use `process.title` as `options.name` if `options.name` is not provided. `options.name` must be alphanumeric only (spaces are supported) and at most 70 characters.

`sudo-prompt` will preserve the current working directory on all platforms. Environment variables can be set explicitly using `options.env`.

**`sudo-prompt.exec()` is different to `child-process.exec()` in that no child process is returned (due to platform and permissions constraints).**

## Behavior
On macOS, `sudo-prompt` should behave just like the `sudo` command in the shell. If your command does not work with the `sudo` command in the shell (perhaps because it uses `>` redirection to a restricted file), then it may not work with `sudo-prompt`. However, it is still possible to use sudo-prompt to get a privileged shell, [see this closed issue for more information](https://github.com/jorangreef/sudo-prompt/issues/1).

On Linux, `sudo-prompt` will use either `pkexec` or `kdesudo` to show the password prompt and run your command. Where possible, `sudo-prompt` will try and get these to mimic `sudo`. Depending on which binary is used, and due to the limitations of some binaries, the name of your program or the command itself may be displayed to your user. `sudo-prompt` will not use `gksudo` since `gksudo` does not support concurrent prompts. Passing `options.icns` is currently not supported by `sudo-prompt` on Linux. Patches are welcome to add support for icons based on `polkit`.

On Windows, `sudo-prompt` will elevate your command using User Account Control (UAC). Passing `options.name` or `options.icns` is currently not supported by `sudo-prompt` on Windows.

## Non-graphical terminal commands only
Just as you should never use `sudo` to launch any graphical applications, you should never use `sudo-prompt` to launch any graphical applications. Doing so could cause files in your home directory to become owned by root. `sudo-prompt` is explicitly designed to launch non-graphical terminal commands. For more information, [read this post](http://www.psychocats.net/ubuntu/graphicalsudo).

## Concurrency
On systems where the user has opted to have `tty-tickets` enabled (most systems), each call to `exec()` will result in a separate password prompt. Where `tty-tickets` are disabled, subsequent calls to `exec()` will still require a password prompt, even where the user's `sudo` timestamp file remains valid, due to edge cases with `sudo` itself, [see this discussion for more information](https://github.com/jorangreef/sudo-prompt/pull/76).

You should never rely on `sudo-prompt` to execute your calls in order. If you need to enforce ordering of calls, then you should explicitly order your calls in your application. Where your commands are short-lived, you should always queue your calls to `exec()` to make sure your user is not overloaded with password prompts.

## Invalidating the timestamp
On macOS and Linux, you can invalidate the user's `sudo` timestamp file to force the prompt to appear by running the following command in your terminal:

```sh
$ sudo -k
```

---
_Source: https://npm.io/package/@vscode/sudo-prompt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
