Skip to content

macOS Local Network Privacy blocks the background service from LAN hosts; fix by shipping a signed .app bundle #58080

Open

Description

@belgaied2

Description

On macOS 15+, the OpenCode background service cannot open TCP connections to LAN addresses (192.168.x.x, 10.x.x.x). The connect fails before any HTTP status is returned, surfacing as EHOSTUNREACH / FailedToOpenSocket and the generic message Cannot connect to API: Was there a typo in the url or port?. Apple-signed clients on the same machine (/usr/bin/curl, /usr/bin/ssh) reach the same host:port at the same moment.

The cause is macOS Local Network Privacy (LNP), described in Apple's TN3179. It is not DNS, not provider configuration, and not a bug in Bun's networking.

Two things combine:

  1. LNP gates outgoing TCP/UDP to local-network addresses and only allows programs whose identity macOS can establish. It is not TCC: there is no tccutil equivalent, MDM cannot configure it, and a program with no bundle identity never gets a prompt and never appears in System Settings > Privacy & Security > Local Network. The denial happens in the network stack, so users only see EHOSTUNREACH.

  2. opencode starts a persistent server through launchctl and it gets reparented to PID 1:

    PID 25455  PPID 1  /opt/homebrew/bin/opencode serve --service
    

    TN3179 exempts command-line tools run from Terminal or SSH, including their children. After reparenting, the service is no longer a child of the terminal and is not a launchd daemon either, so neither exemption applies. The TUI you type into is only a client of 127.0.0.1:49374; the provider and MCP sockets are opened by the detached service.

The shipped binary also has no bundle to attribute: codesign reports Identifier=opencode and a valid Developer ID, but spctl says the code is valid but does not seem to be an app. A bare Mach-O has no CFBundleIdentifier and no NSLocalNetworkUsageDescription, so macOS has nothing to show in an alert and no identity to store a decision against.

The practical result is that the same config works and fails depending on how OpenCode was started:

Context LAN access
opencode --standalone from Terminal.app works
opencode default (serve --service, PPID 1) denied

That difference is the whole bug. It also explains why the failure looks like a runtime networking problem: the denial is applied per process, so every socket from that process fails, whichever HTTP client or model runtime opens it.

Reproduction

  1. On macOS 26.x, configure a remote MCP server or a provider baseURL pointing at a LAN host, e.g. http://192.168.1.47:8000/mcp.
  2. Confirm the host is reachable: curl http://192.168.1.47:8000/health returns 200.
  3. Run opencode normally and invoke the provider/MCP. It fails with FailedToOpenSocket / EHOSTUNREACH.
  4. Run opencode --standalone from Terminal.app with the same config. It connects.

Environment used for the report: macOS 26.7.1 (25G241), OpenCode 2.1.2, remote MCP over plain HTTP on the LAN, no VPN in the failing path.

Proposed fix: ship a minimal signed .app bundle

Give the service a bundle identity and let launchd associate the job with it.

OpenCode.app/
  Contents/
    Info.plist
    MacOS/opencode          # the existing CLI binary
    Resources/

Contents/Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleIdentifier</key>          <string>ai.opencode.cli</string>
  <key>CFBundleExecutable</key>          <string>opencode</string>
  <key>CFBundleName</key>                <string>OpenCode</string>
  <key>CFBundlePackageType</key>         <string>APPL</string>
  <key>CFBundleShortVersionString</key>  <string>2.1.2</string>
  <key>CFBundleVersion</key>             <string>2.1.2</string>
  <key>LSBackgroundOnly</key>            <true/>
  <key>NSLocalNetworkUsageDescription</key>
  <string>OpenCode connects to model servers, MCP servers, and other services on your local network.</string>
</dict>
</plist>

The service registration must point inside the bundle and associate the job with the bundle ID. Two options:

SMAppService (macOS 13+), with the agent plist at Contents/Library/LaunchAgents/<label>.plist. This is the supported path and registers the association automatically.

Plain LaunchAgent, with the association declared explicitly:

<key>ProgramArguments</key>
<array>
  <string>/Applications/OpenCode.app/Contents/MacOS/opencode</string>
  <string>serve</string>
  <string>--service</string>
</array>
<key>AssociatedBundleIdentifiers</key>
<array>
  <string>ai.opencode.cli</string>
</array>

Sign the assembled bundle, not just the executable, so the Info.plist is covered by the signature:

codesign --force --options runtime --timestamp \
  --sign "Developer ID Application: Anomaly Innovations, Inc. (5NZ4Q7NXJ4)" \
  OpenCode.app

Keep the bundle identifier and team stable across releases. The LNP decision is keyed to the designated requirement, so a stable Developer ID signature means the user approves once and keeps the grant through updates.

The desktop app needs the same treatment: NSLocalNetworkUsageDescription in its Info.plist, and the CLI sidecar spawned from inside the bundle so it inherits the app's identity rather than running as an unrelated bare binary.

Why this has to ship upstream

Adding bundle metadata to an already-signed binary breaks its signature:

codesign --verify --deep --strict OpenCode.app
code has no resources but signature indicates they must be present

A user-side wrapper therefore has to be re-signed, and ad-hoc signing replaces the Developer ID with a cdhash-based designated requirement. That requirement changes with every build, so the grant is lost on update and the user is denied again with no prompt. Only you can ship a wrapper that keeps the existing Developer ID identity.

Verification on a real machine

I tested the mechanism locally before filing this. A minimal .app containing a copy of the 2.1.2 binary, ad-hoc signed, with CFBundleIdentifier and NSLocalNetworkUsageDescription, launched by a LaunchAgent carrying AssociatedBundleIdentifiers:

  • First LAN connect failed with errno=65 twice, then macOS presented the local network prompt.
  • After Allow, the same binary connected, and the LAN MCP endpoint worked with no SSH tunnel and no HTTP_PROXY.
  • The grant survived a restart of the service and a reboot.

The same service at PPID 1 without the bundle was denied every time. So the mechanism is confirmed on macOS 26.7.1; the missing piece upstream is only that it must be signed with your Developer ID to be durable.

Workarounds until this ships

  • opencode --standalone from Terminal.app or over SSH. The server stays a child of the terminal, so the exemption applies. Sessions do not persist after the terminal closes.

  • Point at a VPN address instead of a LAN address. LNP covers broadcast-capable interfaces (Wi-Fi, Ethernet) and does not gate tunnelled traffic, so a Tailscale or WireGuard address works.

  • Loopback forward, e.g. ssh -N -L 127.0.0.1:8000:127.0.0.1:8000 user@host. Traffic stays on the LAN and /usr/bin/ssh is Apple-signed.

  • Admin-level subnet exemption, documented in TN3179 since macOS 15.5. It is machine-wide, not per-app, and requires a reboot:

    sudo defaults write com.apple.network.local-network AllowedEthernetLocalNetworkAddresses -array "192.168.1.0/24"
    sudo defaults write com.apple.network.local-network AllowedWiFiLocalNetworkAddresses -array "192.168.1.0/24"
    sudo reboot

Related issues

Acceptance criteria

  • On a clean macOS profile, the first LAN connection from the background service prompts, and the prompt is attributed to OpenCode.
  • After Allow, a provider baseURL, a remote MCP server, and a child process spawned by a tool can each reach an RFC1918 host with no tunnel and no proxy environment variable.
  • After Don't Allow, the error says local network permission is required instead of suggesting the URL or port is wrong.
  • The grant survives a service restart, a reboot, and an OpenCode update.
  • Loopback and public-internet traffic are unaffected in both cases.

Activity

  1. opencode-agent commented on Oct 22, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and for testing the bundle approach locally. I couldn't reproduce this here: the problem depends on macOS Local Network Privacy, and the test environment I have is Linux, which has nothing similar. A maintainer with a Mac will need to check it, by comparing the default opencode (which runs serve --service) with opencode --standalone, using a provider baseURL or remote MCP server on a LAN host.

    The code does match what you describe. The background service is started as a separate process with no link back to the terminal, so it ends up with parent PID 1. OpenCode also ships no macOS bundle metadata (NSLocalNetworkUsageDescription, AssociatedBundleIdentifiers), so there is nothing for macOS to show a prompt for.

    Related reports, most relevant first:

    Until this is looked at, the workarounds you listed still apply: --standalone from Terminal, an SSH loopback forward, a VPN address, or the TN3179 subnet exemption.

  2. Dante-dan commented on Oct 22, 2026

    @Dante-dan
    Contributor

    I traced the current dev service startup and found one distinction that matters for choosing the fix: ServiceConfig.options passes serve --service to spawnServiceContender, which uses detached child-process spawning and unref(). It does not install or start a LaunchAgent through launchctl. PPID 1 alone therefore doesn't establish which code macOS holds responsible for the network access.

    Your bundle experiment is useful evidence, but it changes both app identity and launch mechanism. TN3179 describes responsible-code attribution, but does not provide a direct query for it. The missing observable details are whether the failing service was originally spawned by Terminal, the desktop app, or an existing user LaunchAgent; whether Local Network settings show an entry and its name; and whether allowing that entry changes the same service’s next connection attempt. Could you share whichever of those are available? The existing standalone result and Developer ID verification don't need repeating. The release workflow already signs the macOS CLI with Developer ID, so this needs to distinguish attribution from executable signing.

    That would let us target the current startup path, or propose an associated app/helper lifecycle with an explicit CLI-versus-desktop design. I have only checked the source paths; I haven't reproduced the LAN failure or verified a packaging fix.

  3. professoruss commented on Oct 24, 2026

    @professoruss

    This has been driving me insane since I started using opencode-cli. it even seems as if sometimes macOS ignores the sudo defaults write com.apple.network.local-network AllowedEthernetLocalNetworkAddresses commands randomly (set multiple reboots ago, values still present, restart terminal/herdr/opencode). leaving ssh sessions tunnels open as a workaround is pretty ridiculous

  4. belgaied2 commented on Oct 27, 2026

    @belgaied2
    Author
    Your bundle experiment is useful evidence, but it changes both app identity and launch mechanism. [TN3179](https://developer.apple.com/documentation/technotes/tn3179-understanding-local-network-privacy) describes responsible-code attribution, but does not provide a direct query for it. The missing observable details are whether the failing service was originally spawned by Terminal, the desktop app, or an existing user LaunchAgent; whether Local Network settings show an entry and its name; and whether allowing that entry changes the same service’s next connection attempt. Could you share whichever of those are available? The existing standalone result and Developer ID verification don't need repeating. The release workflow already [signs the macOS CLI with Developer ID](https://github.com/anomalyco/opencode/blob/f7d5b6ffc48223e654b20043a500d315e4bc8053/.github/workflows/publish.yml#L139-L180), so this needs to distinguish attribution from executable signing.
    That would let us target the current startup path, or propose an associated app/helper lifecycle with an explicit CLI-versus-desktop design. I have only checked the source paths; I haven't reproduced the LAN failure or verified a packaging fix.
    

    So, orginally I only ran opencode in the terminal. I use usually iTerm2, sometimes Ghostty and for troubleshooting purposes Terminal.app (the original MacOS terminal app, because it is signed by Apple and wouldn't need any changes to privacy settings). When the agent requests resources from the local network, it fails as if a firewall was in place. Also, a curl performed by the agent would fail, whereas running the /exit command and then curl in the same terminal succeeds. That's what put me on the direction that the opencode would be using launchctl.

    So, to answer your question, it is definitely happening when I run opencode in the terminal.

  5. vjm commented on Oct 30, 2026

    @vjm

    I encountered this with the macOS desktop app on v2.2.4 when connecting to a self-hosted OpenCode server on my LAN.

    Symptoms:

    • The desktop app showed “Could not connect to server.”
    • The same server and credentials worked in the browser and on another Mac.
    • curl on the affected Mac successfully connected, validated the TLS certificate, and returned HTTP 200.
    • OpenCode was missing from System Settings → Privacy & Security → Local Network on the affected Mac. It was listed on the working Mac.
    • Connecting through WireGuard worked, but did not create a Local Network permission entry.

    What fixed it for me:

    1. Downgrade the desktop app to v1.
    2. Try to connect to local network to trigger the permission request
    3. Then upgrade back to v2.2.4.
      Afterward, OpenCode appeared in the Local Network permission list, and direct LAN access worked with WireGuard disconnected, including after fully quitting and reopening OpenCode.

    I can’t confirm which step established the permission or changed the app attribution, but the downgrade/upgrade sequence resolved it on this machine.

  6. guruchill commented on Nov 23, 2026

    @guruchill

    Reproduced on macOS 27.2.1 (26B131), OpenCode Desktop 2.4.1 (Apple Silicon), with an OpenAI-compatible provider baseURL at http://192.168.1.190:8080/v1.

    • /usr/bin/curl from the same machine returns 200. The provider fails with EHOSTUNREACH and retries indefinitely (Attempt 4 – retrying in 6s). webfetch and the in-app browser also fail for the same LAN host.
    • The server is ~/Library/Application Support/ai.opencode.desktop/cli/2.4.1-arm64/opencode-cli serve --service, reparented to PID 1.
    • OpenCode never appears in System Settings → Privacy & Security → Local Network, and no prompt is ever shown. /Applications/OpenCode.app/Contents/Info.plist has no NSLocalNetworkUsageDescription.
    • Quitting the desktop app leaves the service running. Killing it so a fresh service is spawned by the relaunched app does not help, so this isn't the stale-service case described above.
    • Router (192.168.1.1) and internet traffic are unaffected.

    The available workarounds are a machine-wide subnet exemption, a tunnel, or giving up the desktop app for --standalone. None of these is acceptable for a desktop app, which should be able to ask for Local Network permission like any other Mac app. Please give the service a bundle identity the desktop app's permission covers, and add NSLocalNetworkUsageDescription. Until then, please report a Local Network denial as such rather than "check the network connection / typo in the url".

  7. sumkire commented on Nov 26, 2026

    @sumkire

    Additional reproduction: restarting the service from a terminal restores LAN access

    Adding a data point relevant to the responsible-process attribution question.

    • opencode: v2.4.2, ~/.opencode/bin/opencode serve --service
    • OS: macOS 27.2.1 (Darwin 27.2.0, arm64), zsh, TERM_PROGRAM=rex
    • Provider: custom OpenAI-compatible, baseURL: http://192.168.31.133:40040/v1
    • While the old service was failing:
      • /usr/bin/curl http://192.168.31.133:40040/v1/models from the same machine returned 200.
      • A new session through the shared service still failed with EHOSTUNREACH / "Was there a typo in the url or port?"
      • opencode --standalone from the terminal worked.
      • opencode api get /api/provider showed the correct baseURL.
    • The failing service had PPID 1.
    • After opencode service restart from the terminal, the new service had PPID 5187 (not 1) and the same config worked.
    • OpenCode never appeared in System Settings → Privacy & Security → Local Network.
    • opencode.log contained 0 EHOSTUNREACH lines at INFO level.

    This distinguishes a fresh service started from a terminal (LAN access works) from the detached/reparented service (LAN access fails), which points to Local Network Privacy attribution rather than provider or URL configuration.

  8. jabbas commented on Nov 27, 2026

    @jabbas

    Another data point from the desktop app's own connection path, not the background service. Desktop 2.4.1 (also 2.3.2), macOS 26, adding an OpenCode server on another LAN machine via "Add server" (pairing link or password) fails with "Can't connect to http://:4096. Check that this device can access the server, and try again."

    • The same server works from Chrome on the same Mac, from opencode --server http://<host>:4096, from curl, and from the Android app. CORS is fine, and app and server are on the same version.
    • tccutil reset All ai.opencode.desktop plus a full restart does not bring up a Local Network prompt. OpenCode is not listed under Privacy & Security → Local Network.
    • OpenCode.app/Contents/Info.plist (2.4.1) has NSAppTransportSecurity / NSAllowsLocalNetworking, but no NSLocalNetworkUsageDescription and no NSBonjourServices.
    • Workaround: an SSH tunnel to 127.0.0.1 on the Mac, or the web UI in a browser.

    So the missing NSLocalNetworkUsageDescription also blocks the desktop app itself from reaching LAN OpenCode servers, not only the spawned service. Adding it to the macOS Info.plist (electron-builder mac.extendInfo) is needed in addition to the UUID and bundle-identity fixes discussed here.

  9. liftoff1968 commented on Nov 28, 2026

    @liftoff1968

    Related macOS 27 issue: empty ARP table even in standalone mode

    I would like to add a potentially related but distinct reproduction.

    Environment:

    • macOS 27.x
    • Apple Silicon
    • OpenCode 2.4.2
    • Installed via Homebrew

    Observed behavior:

    • /usr/sbin/arp -an returns numerous entries in the normal macOS Terminal.
    • The same command returns an empty ARP table when executed through OpenCode.
    • opencode --standalone does not resolve the issue.
    • The macOS Local Network permission dialog does not allow selecting the OpenCode CLI binary.

    Code signing information:

    • Valid Developer ID Application signature: Anomaly Innovations, Inc.
    • Hardened Runtime enabled.
    • Info.plist=not bound

    Potential cause:

    The OpenCode executable does not have the following entitlement:

    com.apple.developer.networking.topology-observation

    Unlike the LAN connectivity problem described in this issue, the ARP-table problem persists in standalone mode.

    This may be related to the network topology observation restrictions introduced in macOS 27 rather than ordinary Local Network Privacy.

    Could the maintainers investigate whether this entitlement is required for network diagnostic commands executed by OpenCode?

    Should this be tracked as a separate issue?

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions