failClosed beforeShellExecution: spawn /bin/zsh ENOENT blocks Shell though hook is bash and /bin/zsh exists

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Agent Shell calls that match a beforeShellExecution hook with failClosed: true are blocked by a Cursor-internal spawn failure. The configured hook command is bash scripts/deliver.sh gate, but ExtHost fails with spawn /bin/zsh ENOENT before the hook produces any stdout. The agent UI treats that as a fail-closed denial.

On this machine /bin/zsh exists (SHELL=/bin/zsh). The same bash …/deliver.sh gate succeeds when run via the agent Shell tool outside the hook path.

Verbatim agent error:

Hook "bash scripts/deliver.sh gate" failed with exit code 1: execution error: spawn /bin/zsh ENOENT
Tool blocked because this hook is configured to fail closed (block when it fails).

Hooks log excerpt:

Command: bash scripts/deliver.sh gate (3ms) exit code: 1
INPUT: { ..., "sandbox": true, "cwd": "", "cursor_version": "3.27.22", ... }
OUTPUT: (empty)
STDERR: execution error: spawn /bin/zsh ENOENT

exthost.log:

[ExtHostShellExec] Hook execution error: spawn /bin/zsh ENOENT

Steps to Reproduce

  1. Install/enable a plugin or user beforeShellExecution hook with failClosed: true, for example:
{
  "version": 1,
  "hooks": {
    "beforeShellExecution": [
      {
        "command": "bash scripts/deliver.sh gate",
        "matcher": "gh pr create|git push",
        "timeout": 10,
        "failClosed": true
      }
    ]
  }
}
  1. In Agent chat, run a Shell command that matches the matcher (e.g. git push or gh pr create).
  2. Observe the agent Shell call blocked with execution error: spawn /bin/zsh ENOENT.
  3. Check Output → Hooks / cursor.hooks.*.log: empty OUTPUT, STDERR execution error: spawn /bin/zsh ENOENT, and exthost [ExtHostShellExec] Hook execution error: spawn /bin/zsh ENOENT.
  4. Confirm /bin/zsh exists on the host and that running the same bash …/deliver.sh gate via agent Shell (without matching the gated command) works.

Expected Behavior

ExtHost should run the configured bash hook command (or an available shell) and not fail spawning /bin/zsh when it exists on the host.

Alternatively: a Cursor-internal failure to spawn the hook should be recoverable / not treated as a policy denial under failClosed (same ask as the MainThreadShellExec not initialized report linked in Additional Information).

Operating System

MacOS

Version Information

Cursor 3.27.22 · VSCode 1.128.0 · commit b1aa50cb6db8 · macOS 27.2.0 Darwin arm64

For AI issues: which model did you use?

Grok 4.5 (Cursor agent)

For AI issues: add Request ID with privacy disabled

Conversation id: 7aa4ed92-e56d-4857-b3e7-82c8769115f1
Generation id (one failure): a125c309-f0b6-4d9c-88f4-dad75ca990c2

Additional Information

Related (max 2 links for new-user limit):

  1. Closest failClosed internal-spawn issue (different error string; staff invited fresh reports): Agent Shell hard-locks: fail-closed beforeShellExecution + MainThreadShellExec not initialized
  2. Different family (zsh missing on remote/devcontainer — NOT this case; /bin/zsh exists here): Cursor Agent shell commands not working in devcontainer

Notable hook INPUT during failure: sandbox true and empty cwd.

Does this stop you from using Cursor

Sometimes - I can sometimes use Cursor

Follow-up: hypothesis, empty cwd, plugin mitigation result

Explicit runner hypothesis

ExtHost appears to spawn $SHELL (/bin/zsh) to run hook command strings rather than execFileing the configured argv / a shebang script. That spawn returns ENOENT inside the hook environment even though /bin/zsh exists on the host (SHELL=/bin/zsh, ls /bin/zsh OK). The configured command (bash scripts/…) never starts — Hooks log shows empty OUTPUT and STDERR execution error: spawn /bin/zsh ENOENT.

Elevate: sandbox: true + empty cwd

During the failing runs, hook INPUT included sandbox: true and cwd: "". Please treat those as first-class repro facts. Empty cwd also means a successfully started hook that cds from stdin cannot find the agent workspace (our gate then fail-opens when git rev-parse fails outside a repo). Expected: pass a real workspace cwd (or non-empty workspace_roots) into beforeShellExecution INPUT.

Ask: fail-open on runner spawn failures

Please distinguish:

  1. Runner failure — ExtHost cannot spawn the hook process (spawn /bin/zsh ENOENT, MainThreadShellExec not initialized, etc.) → should not be treated as a policy denial under failClosed (same family as Agent Shell hard-locks: fail-closed beforeShellExecution + MainThreadShellExec not initialized).
  2. Intentional hook deny — hook process starts and returns permission: deny JSON (or a documented non-zero from a live process) → failClosed / deny as designed.

Plugin mitigation measurement (awre-delivery)

Per create-hook guidance we switched the plugin hook command from bash scripts/deliver.sh gate to an executable shebang script (hooks/cursor-gate.sh with #!/usr/bin/env bash). Matcher tightened to word boundaries so incidental substrings do not fire the hook as often.

Measured on Cursor 3.27.22 (this machine), after installing the shebang entrypoints into the plugin cache / ~/.cursor/hooks.json:

  • Before: matching Shell (git push / incidental matcher text) → blocked with spawn /bin/zsh ENOENT + failClosed.
  • After: matching Shell proceeds without ENOENT (shebang path appears to avoid the broken $SHELL wrap).
  • Separately: when we run the gate script by hand with a real cwd in stdin JSON, dirty worktree correctly denies. Under the agent hook path, empty cwd remains a concern for policy hooks that need the workspace.

This is a plugin workaround, not a fix for ExtHost. Please still fix spawn-$SHELL / failClosed-on-runner-error, and populate hook cwd.

PR (pending one approving review / merge to main, then Customize refresh): https://github.com/awresports/standards/pull/143

Minor matcher note

The old matcher gh pr create|git push also fires on incidental substrings (e.g. installer scripts that mention those phrases), which only increases how often the broken spawn path is hit — not the root cause.

Untested idea, but worth ruling out. In Node, spawn reports ENOENT with the shell path when the working directory does not exist, not only when the shell is missing. The Node docs: “If given, but the path does not exist, the child process emits an ENOENT error and exits immediately.” I reproduced it on Node 22: spawn('echo ok', {shell: '/bin/bash', cwd: '/nonexistent-dir'}) fails with “spawn /bin/bash ENOENT” even though /bin/bash exists.

Your log shows "sandbox": trueso my guess is the sandboxed mode spawns from a directory that does not exist for that process. Two quick tests: run the same hook with sandbox off, and point the hook command at an absolute script path. If it passes with sandbox off, that narrows it to the sandbox spawn path, which only the Cursor team can fix.

Also, with failClosed: true a hook crash blocks the action, so every shell call stays blocked until this is fixed.

Hi Dave, thanks for the detailed report!

Sattyam’s guess is right: /bin/zsh exists, but the folder the hook runs from doesn’t. That’s the plugin’s install folder for plugin hooks, or the hooks.json folder for user hooks. A plugin update can remove that folder while the hook still points at it, so the spawn fails right away with that misleading error. This is probably also why the shebang change seemed to fix it: reinstalling the plugin refreshed the path.

Until there’s a fix, reload the window after plugin updates. Or set failClosed: false for now if an occasional unchecked command is acceptable.

I’ve attached your report to the internal issue where we’re tracking this!

Confirming Colin’s diagnosis, and correcting the 1 November note that the shebang script fixed it.

That success was the reinstall refreshing the path. The hook command is already the shebang script hooks/cursor-gate.sh, not bash scripts/deliver.sh gate. After the next marketplace refresh, an open window stays bound to the old plugin install directory, which the refresh deletes.

Today (5 November 2026) this window was still bound to:

~/.cursor/plugins/cache/awresports-standards/awre-delivery/5ea1751dd09daf6524f23ffc37c12ff034dfc781

That directory is gone. The only install on disk is a01abbec59c0657196721c16c7f9ebeceab644b1. /bin/zsh exists. git push and gh pr create never started the gate script. The agent error was:

Hook "hooks/cursor-gate.sh" failed with exit code 1: execution error: spawn /bin/zsh ENOENT
Tool blocked because this hook is configured to fail closed (block when it fails).

Reload Window points the hook at the new install. The next refresh that replaces the cache while the window stays open breaks it the same way. Changing the hook command cannot run a process whose working directory has already been deleted.