{"record":{"id":"4ea5717d77af7ab2","repo":"docmirror/dev-sidecar","slug":"networksetup-exit-code-14","errorCode":null,"errorMessage":"networksetup 命令需要管理员权限（exit code 14），正在弹出系统授权对话框...","messagePattern":"networksetup 命令需要管理员权限（exit code 14），正在弹出系统授权对话框\\.\\.\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/src/shell/scripts/set-system-proxy/index.js","lineNumber":658,"sourceCode":"      // 设置排除域名\n      const excludeIpStr = getProxyExcludeIpStr('\" \"')\n      cmds.push(`networksetup -setproxybypassdomains \"${wifiAdaptor}\" \"${excludeIpStr}\"`)\n    } else { // 关闭代理\n      // https + http\n      cmds = [\n        `networksetup -setsecurewebproxystate \"${wifiAdaptor}\" off`,\n        `networksetup -setwebproxystate \"${wifiAdaptor}\" off`,\n      ]\n    }\n\n    // 先尝试直接执行；若因权限不足（exit code 14）失败，弹出系统授权对话框后重试\n    try {\n      for (const cmd of cmds) {\n        await exec(cmd)\n      }\n    } catch (e) {\n      if (e.code === MACOS_NETWORKSETUP_PERMISSION_ERROR_CODE) {\n        log.warn('networksetup 命令需要管理员权限（exit code 14），正在弹出系统授权对话框...')\n        await sudoExecMac(cmds.join(' && '))\n        log.info('以管理员权限执行 networksetup 命令成功')\n      } else {\n        throw e\n      }\n    }\n\n    // 设置环境变量\n    if (setEnv) {\n      if (ip != null) {\n        loadConfig()\n        writeProxyEnvFile(ip, port, config.get().proxy.proxyHttp)\n        addProxyEnvToShellProfile()\n      } else {\n        removeProxyEnvFromShellProfile()\n      }\n    }\n  },","sourceCodeStart":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/docmirror/dev-sidecar/blob/7710cd56cce760c708f30b01d2d4056eb8c402d5/packages/core/src/shell/scripts/set-system-proxy/index.js#L640-L676","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before — fails with exit code 14 for standard users\nawait exec('networksetup -setwebproxy \"Wi-Fi\" 127.0.0.1 31181')\n// error: ** Error: You don't have permission to change the system preferences.\n\n// after — the library escalates automatically; user approves the dialog,\n// or pre-grant rights so no escalation is needed:\nsudo dscl . -append /Groups/admin GroupMembership <youruser>","handlingStrategy":"try-catch","validationCode":"const { execSync } = require('node:child_process')\nfunction canModifyNetworkSettings() {\n  try {\n    execSync('networksetup -setwebproxy \"Wi-Fi\" 127.0.0.1 1', { stdio: 'ignore' })\n    execSync('networksetup -setwebproxystate \"Wi-Fi\" off', { stdio: 'ignore' })\n    return true\n  } catch (e) {\n    if (e.status === 14) console.warn('Admin authorization required for networksetup')\n    return false\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await DevSidecar.api.config.set('proxy.enable', true)\n} catch (e) {\n  if (e.code === 14 || /permission/i.test(e.message)) {\n    console.error('User denied admin authorization; set macOS proxy manually')\n  } else {\n    throw e\n  }\n}","preventionTips":["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"],"tags":["macos","networksetup","permission-denied","sudo","exit-code-14"],"backgroundTag":"networksetup-permission-denied","analyzedSha":"7710cd56cce760c708f30b01d2d4056eb8c402d5","analyzedAt":"2026-08-31T22:07:07.234Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}