Skip to content

Source host daemon injects an unbuilt CLI into sandboxed threads from fresh worktrees #1970

Closed

Description

@ymichael

Summary

Starting bb from source in a fresh worktree can inject apps/cli/bin/bb into agent shells before its gitignored dist/index.js runtime exists. A sandboxed thread that runs bb then tries to bootstrap the CLI by writing into the source daemon worktree and fails with Operation not permitted; the injected CLI should be ready before any thread starts.

Versions and environment

  • bb: 0.39.0, from source at abbc3f91ccc4215889eaa317b0b234adc3cc6c1a
  • macOS 26.5.1 (25F80), Apple Silicon
  • Node v22.23.1; pnpm 9.15.0
  • Codex CLI 0.147.0
  • Source daemon worktree: env_ac99xb9nqm
  • Reproducing sandboxed thread worktree: env_bnwjr7st7r
  • Thread: thr_kbuh8i42fv

Steps to reproduce

  1. Create a fresh source checkout/worktree where apps/cli/dist/index.js does not exist.
  2. Run pnpm dev from that checkout.
  3. Create a sandboxed agent thread in another managed worktree.
  4. In that thread, run bb status --json.

The source host daemon resolves the local wrapper for shell injection (source), but its Turbo dev task does not build @bb/cli first (source). The wrapper therefore falls into its lazy build path (source).

Expected vs actual

Expected: the injected bb CLI is already runnable and bb status --json returns status without modifying the daemon checkout.

Actual:

$ bb status --json
• turbo 2.8.3
• Packages in scope: @bb/cli, @bb/scripts
• Running build in 2 packages
• Remote caching disabled, using shared worktree cache
 WARNING  error creating log file directory: Custom { kind: PermissionDenied, error: Error { kind: CreateDir, source: Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }, path: "/Users/michael/.bb/worktrees/env_ac99xb9nqm/bb/packages/scripts/.turbo" } }
  x Internal errors encountered: error with cache: Failed to replay logs:
  | Cannot write logs: failed to create directory `/Users/michael/.bb/
  | worktrees/env_ac99xb9nqm/bb/packages/scripts/.turbo`

exit code 1

Evidence

The failing shell had BB_CLI set to the wrapper in env_ac99xb9nqm, while the active thread ran in env_bnwjr7st7r. Building the CLI inside the active worktree did not help because the built CLI re-executed the injected external BB_CLI; unsetting BB_CLI and running the local wrapper succeeded.

What was ruled out

  • The target worktree CLI works after a local build when the injected BB_CLI override is removed.
  • This is not a packaged-production CLI failure; the production bundle supplies its own executable directory.
  • The permission error is not a general inability to run bb; it comes from the lazy build targeting the separate daemon checkout.
  • Searches for fresh worktree CLI, BB_CLI worktree, Operation not permitted .turbo, and Missing built bb CLI found no matching issue or PR.

Suggested priority and effort

Medium priority, small effort. It blocks all injected bb commands for sandboxed threads when source development begins from an unbuilt worktree, with an unintuitive environment-unset workaround.

AGENT GENERATED: by GPT-5

Activity

  1. added a commit that references this issue on Aug 19, 2026
    35732c5
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