fnm env fails in Cursor agent shells (non-interactive zsh + sandboxed writes)
Author: kharandziukCreated Jul 2, 2026Updated Sep 3, 2026
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
.zshrcis not sourced in the agent shell (interactive=no), so--use-on-cdnever runs and.nvmrcis not applied automatically.fnm envfails 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?
Source: Schniz/fnm