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

  1. Approve the macOS authorization dialog that appears (enter an administrator's credentials) — this is the designed flow and completes the proxy setup
  2. 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`)
  3. 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
  4. 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

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


AI-assisted analysis of docmirror/dev-sidecar@7710cd56cc (2026-08-31). Data as JSON: /api/errors/4ea5717d77af7ab2. Report an issue: GitHub.