docmirror/dev-sidecar · warning
networksetup 命令需要管理员权限(exit code 14),正在弹出系统授权对话框...
Error message
networksetup 命令需要管理员权限(exit code 14),正在弹出系统授权对话框...
What it means
Warning logged by the macOS system-proxy setter when executing the `networksetup -setwebproxy/-setsecurewebproxy/-setproxybypassdomains` commands fails with exit code 14, macOS's 'You don't have permission to change the system preferences' error. The code detects this specific code (MACOS_NETWORKSETUP_PERMISSION_ERROR_CODE = 14) and escalates to a privileged run via @vscode/sudo-prompt, which pops the system authorization dialog so the user can approve admin execution. Any other error code is re-thrown.
Source
Thrown at packages/core/src/shell/scripts/set-system-proxy/index.js:658
// 设置排除域名
const excludeIpStr = getProxyExcludeIpStr('" "')
cmds.push(`networksetup -setproxybypassdomains "${wifiAdaptor}" "${excludeIpStr}"`)
} else { // 关闭代理
// https + http
cmds = [
`networksetup -setsecurewebproxystate "${wifiAdaptor}" off`,
`networksetup -setwebproxystate "${wifiAdaptor}" off`,
]
}
// 先尝试直接执行;若因权限不足(exit code 14)失败,弹出系统授权对话框后重试
try {
for (const cmd of cmds) {
await exec(cmd)
}
} catch (e) {
if (e.code === MACOS_NETWORKSETUP_PERMISSION_ERROR_CODE) {
log.warn('networksetup 命令需要管理员权限(exit code 14),正在弹出系统授权对话框...')
await sudoExecMac(cmds.join(' && '))
log.info('以管理员权限执行 networksetup 命令成功')
} else {
throw e
}
}
// 设置环境变量
if (setEnv) {
if (ip != null) {
loadConfig()
writeProxyEnvFile(ip, port, config.get().proxy.proxyHttp)
addProxyEnvToShellProfile()
} else {
removeProxyEnvFromShellProfile()
}
}
},View on GitHub (pinned to 7710cd56cc)
Solutions
- Approve the macOS authorization dialog that appears (enter an administrator's credentials) — this is the designed flow and completes the proxy setup
- Make your user an administrator or add it to the group allowed to modify network settings, so plain networksetup works without escalation (test: `networksetup -setwebproxy Wi-Fi 127.0.0.1 31181`)
- If the dialog never appears (SSH/daemon/automation), run DevSidecar once from an interactive desktop session, or pre-authorize networksetup changes for the user in your MDM profile
- If you deny or cannot use admin rights, set the proxy manually in System Settings > Network > Proxies and disable automatic system proxy in DevSidecar config
Example fix
// before — fails with exit code 14 for standard users
await exec('networksetup -setwebproxy "Wi-Fi" 127.0.0.1 31181')
// error: ** Error: You don't have permission to change the system preferences.
// after — the library escalates automatically; user approves the dialog,
// or pre-grant rights so no escalation is needed:
sudo dscl . -append /Groups/admin GroupMembership <youruser> Defensive patterns
Strategy: try-catch
Validate before calling
const { execSync } = require('node:child_process')
function canModifyNetworkSettings() {
try {
execSync('networksetup -setwebproxy "Wi-Fi" 127.0.0.1 1', { stdio: 'ignore' })
execSync('networksetup -setwebproxystate "Wi-Fi" off', { stdio: 'ignore' })
return true
} catch (e) {
if (e.status === 14) console.warn('Admin authorization required for networksetup')
return false
}
} Try / catch
try {
await DevSidecar.api.config.set('proxy.enable', true)
} catch (e) {
if (e.code === 14 || /permission/i.test(e.message)) {
console.error('User denied admin authorization; set macOS proxy manually')
} else {
throw e
}
} Prevention
- Have administrator credentials ready — an authorization dialog appears for standard users
- Run the app from an interactive desktop session so the sudo dialog can be shown
- Pre-grant network-setting rights to the user (admin group or MDM profile) to avoid escalation
- Never disable the authorization dialog in automation; instead pre-configure the proxy or skip system-proxy automation
When it happens
Trigger: executor.mac() on enabling or disabling the proxy where the current user is not a member of the network configuration admin group / lacks rights to change network settings without authorization — typical after macOS security policy changes, on managed/MDM Macs, or when the app is run by a standard (non-admin) user.
Common situations: Standard (non-admin) macOS accounts; MDM-restricted machines where the authorization dialog is blocked; automation contexts where no user can approve the sudo dialog; users denying the authorization prompt.
Related errors
- macOS 代理服务检测:未通过设备名匹配到网络服务,尝试备用方法
- macOS 代理服务检测:获取网络服务列表失败:
- macOS 代理服务检测:未通过服务列表找到可用网络服务
- macOS 代理服务检测:获取所有网络服务列表失败:
- 未找到可用的 macOS 网络服务,无法设置系统代理
AI-assisted analysis of docmirror/dev-sidecar@7710cd56cc (2026-08-31).
Data as JSON: /api/errors/4ea5717d77af7ab2.
Report an issue: GitHub.