Skip to content

opencode template: sandbox ships opencode-ai without its postinstalled binary — "postinstall script was not run" on first run (v1.18.12) #395

Closed

Description

@wz-gsa

Summary

A freshly created opencode sandbox fails on first run because the bundled opencode-ai npm package is present but its postinstall step never ran, so the platform binary was never fetched. Launching the agent errors with:

Error: opencode-ai's postinstall script was not run.

This occurs when using --ignore-scripts during installation, or when using a
package manager like pnpm that does not run postinstall scripts by default.

To fix this, run the postinstall script manually:
  cd node_modules/opencode-ai && node postinstall.mjs

opencode has required this postinstall step to fetch its binary since v1.15.1 (see anomalyco/opencode#27906). The sandbox-templates:opencode-docker image appears to install opencode-ai at build time in a way that skips lifecycle scripts, so the binary is missing in the shipped image.

Environment

  • macOS (Apple Silicon)
  • sbx v0.37.1
  • image: docker/sandbox-templates:opencode-docker (freshly pulled)
  • [email protected], installed at /usr/local/share/npm-global/lib

Evidence it is a build-time script-skip, not a runtime setting

Inside the running sandbox:

$ npm ls -g opencode-ai
/usr/local/share/npm-global/lib
`-- [email protected]

$ npm config get ignore-scripts
false

So ignore-scripts is false at runtime — the package is installed but its postinstall never executed, which points to the image being built with a scripts-skipping installer (e.g. npm ci --ignore-scripts, or pnpm/bun which skip postinstall by default).

Running the postinstall manually fixes it:

$ cd "$(npm root -g)/opencode-ai" && node postinstall.mjs
$ opencode --version
1.18.12

Impact

Every new opencode sandbox created from the current image is broken on first launch until the user manually runs node postinstall.mjs inside the sandbox.

Requested fix

Build the opencode-docker template so opencode-ai's postinstall runs (don't pass --ignore-scripts; if using pnpm/bun, run the postinstall explicitly or allowlist it), so the platform binary is present in the shipped image.

Workaround (for others hitting this)

Inside the sandbox:

cd "$(npm root -g)/opencode-ai" && node postinstall.mjs

Possibly related

Activity

  1. wz-gsa commented on Aug 4, 2026

    @wz-gsa
    Author

    Additional context — reproduced by more than one macOS user, and a note on severity + the reliable workaround.

    Severity: the sandbox is created but cannot be launched. sbx run <sandbox> fails at the agent-launch step (opencode's postinstall guard fires and exits), so the sandbox exists but never becomes usable via run. Importantly, you cannot fix it from a run — sbx run re-launches opencode each time and re-hits the same error.

    Reliable workaround (confirmed): apply the fix with sbx exec, which runs a command in the sandbox without launching the agent:

    sbx ls                                   # find the created sandbox name
    sbx exec <sandbox-name> -- sh -c 'cd "$(npm root -g)/opencode-ai" && node postinstall.mjs'
    sbx exec <sandbox-name> -- opencode --version   # confirms the binary now resolves

    After that, sbx run <sandbox-name> attaches normally. (If sbx exec reports the sandbox isn't running, sbx start <sandbox-name> first.)

    Confirmed on [email protected], sbx v0.37.1, macOS/Apple Silicon: sbx run kept failing with the postinstall error, while sbx exec … -- opencode --version succeeded and got the sandbox past it.

    Restating the root cause for triage: on first launch, the shipped opencode-docker image has the opencode-ai npm package present but its postinstalled platform binary missing (npm config get ignore-scripts is false at runtime, so it is a build-time lifecycle-script skip, not a runtime setting). opencode has required this postinstall to fetch its binary since v1.15.1 (anomalyco/opencode#27906). Building the image so opencode-ai's postinstall runs (or running it explicitly at build) would ship a working binary and remove the need for the manual step above.

  2. slowcommit commented on Aug 4, 2026

    @slowcommit

    Thanks for the workaround. The same problem occurs on Windows as well.

  3. ericcurtin commented on Oct 1, 2026

    @ericcurtin

    Hi @wz-gsa, thanks for the detailed report and workaround! This is fixed from v0.39.0: the opencode template now runs the opencode-ai postinstall step when the image is built, and the build checks opencode --version. Please recreate the sandbox to pick up the current image, and reopen this if it still fails.

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