Skip to content

[BUG] v2 fails under filesystem sandboxe #52458

Closed

Description

@antoinetanzilli-cure51

Description

Detached spawn chdir($HOME) + config discovery walks to / treating EPERM as fatal with opencode v2.0.21 (macOS arm64); macOS Seatbelt sandbox (w/ nono 0.79.0) granting the project workdir but not $HOME or its ancestors. Both start modes affected (managed background service and --standalone).

Suggested fixes:

  1. spawnServiceContender: pass an explicit cwd (e.g. process.cwd() or a granted dir) so the detached child never needs $HOME access.
  2. FSUtil.resolve: catch PermissionDenied alongside NotFound — treat unreadable as absent. Makes the ancestor walk safe under any sandbox.
  3. Optionally bound the walk (stop at $HOME) instead of probing candidates at every level to /.

Plugins

none

OpenCode version

v2.0.21

Steps to reproduce

  1. opencode serve --service (or plain opencode) under a profile that doesn't grant $HOME:

    Error: EPERM: operation not permitted, getcwd '/path/to/project' -> '/Users/<user>'
        at chdir (unknown)
    Error: Server process exited with code 1
    

    spawnServiceContender (packages/client/src/service-conteder.ts) spawns with { detached: true, ... } and no cwd; the runtime's detached-spawn path performs an internal chdir targeting $HOME (observed: at chdir, error formatted getcwd '<cwd>' -> '<home>'). Home-denying sandboxes kill every start at this spawn.

  2. After granting chdir($HOME), the TUI starts but /api/location and /api/fs/list
    return 500:

    PlatformError: Unknown: FileSystem.realPath (/Users/antoine)
        at FileSystem.resolve
        at ConfigDiscovery.discover
        at ServerProcess.start
      [cause]: Error: EPERM: operation not permitted, lstat '/Users/<user>'
    

    ConfigDiscovery.discover (packages/core/src/config/discovery.ts) walks from the project to / (fs.up({ targets: ["."], start: location.directory })), resolving every ancestor dir and five candidate paths per level (.claude, .agents, .opencode, opencode.json[c]). FSUtil.resolve (packages/util/src/fs-util.ts) only catches NotFound; any other errno is Effect.orDie, so the first unreadable ancestor kills startup with a bare 500.

Screenshot and/or share link

No response

Operating System

macOS 26.7

Terminal

Ghostty

Activity

  1. changed the title [-]v2 fails under filesystem sandboxe[/-] [+][BUG] v2 fails under filesystem sandboxe[/+] on Oct 1, 2026
  2. github-actions commented on Oct 1, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

    • #50951: Reports the same macOS EPERM in ConfigDiscovery.discover/FileSystem.resolve causing HTTP 500 responses when a project folder is inaccessible.
  3. Starefossen commented on Oct 8, 2026

    @Starefossen

    Also on 2.0.24 under macOS Seatbelt. It is not just the ancestor walk: discovery.ts:28-32 always resolves ~/.claude and ~/.agents, so denying read on an existing ~/.claude is enough to get a 500. Allowing file-read-metadata does not help; Bun's realpath needs file-read-data.

    Fix: treat PermissionDenied like NotFound in FSUtil.resolve (fs-util.ts:105-111), as skill scanning already does (compatibility.ts:43).

  4. Happycoil commented on Oct 15, 2026

    @Happycoil

    Still exists in 2.0.29. One-line repro:

    OPENCODE_PRINT_LOGS=1 sandbox-exec -p "(version 1)(allow default)(deny file-read* (subpath \"$HOME/.agents\"))" \
      opencode run --standalone --print-logs "hi"
    
  5. Tarquinen commented on Oct 20, 2026

    @Tarquinen
    Member

    This was fixed by #55817. It mentioned this issue as related rather than closing it, so GitHub didn't close it automatically. Closing as completed. If you still see this on the latest OpenCode, please open a new issue with details.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

  6. antoinetanzilli-cure51 commented on Oct 20, 2026

    @antoinetanzilli-cure51
    Author

    Confirmed using 2.1.0, it works! Thanks!

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

Metadata

Metadata

Assignees

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