Skip to content

fnm env fails in Cursor agent shells (non-interactive zsh + sandboxed writes) #1575

Description

@kharandziuk

Context

Cursor runs AI agent commands in a dedicated shell, not the integrated terminal. That shell sets CURSOR_AGENT=1, is non-interactive login zsh, and often runs inside a sandbox that only allows writes inside the workspace.

Projects pin Node via .nvmrc (e.g. 20.19.6). In a normal interactive terminal, fnm works as expected.

Setup

  • OS: macOS
  • Shell: zsh
  • fnm: Homebrew (/opt/homebrew/bin/fnm)
  • Interactive terminal (.zshrc):
    eval "$(fnm env --use-on-cd --shell zsh)"
  • Agent shell (.zshenv, sourced on every zsh invocation):
    if [[ -n "$CURSOR_AGENT" ]]; then
      eval "$(fnm env)"
    fi

Problem

  1. .zshrc is not sourced in the agent shell (interactive=no), so --use-on-cd never runs and .nvmrc is not applied automatically.

  2. fnm env fails when initializing in the agent shell:

    error: Can't create the symlink for multishells at
    "/Users/local_admin/.local/state/fnm_multishells/<pid>_<ts>".
    Operation not permitted (os error 1)
    

    fnm creates a new multishell symlink on every shell start. The agent sandbox blocks writes under ~/.local/state/.

any idea how to fix it? or any workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions