Agent editing files with shell/python - Permission denied from Read and StrReplace tools when using git worktrees

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

When the AI agent uses built-in file tools (StrReplace, Write, etc.) to modify files under the workspace, the operation fails with “Write permission denied”. The same files can be edited without error using the integrated terminal (e.g. python/sed writing to the same path).

Steps to Reproduce

Open folder /home/user/repo/worktrees/featureX as the workspace root.
Enable Agent mode.
Ask the agent to edit a file (e.g. a one-line comment change) using normal apply/edit tools.
Observe tool result: Write permission denied.
In the integrated terminal:
test -w && echo ok
and/or append a line with a shell redirect — succeeds.

Actual Behavior:
Agent file tools report Write permission denied; terminal writes to the same path work.

Expected Behavior

Agent file tools should write to any file that is writable by the user and inside the opened workspace, consistent with the terminal

Operating System

Linux

Version Information

Version: 2.6.20
VSCode Version: 1.105.1
Commit: b29eb4ee5f9f6d1cb2afbc09070198d3ea6ad760
Date: 2026-03-17T01:50:02.404Z
Build Type: Stable
Release Track: Default
Electron: 39.8.1
Chromium: 142.0.7444.265
Node.js: 22.22.1
V8: 14.2.231.22-electron.0
OS: Linux x64 6.8.0-106-generic

For AI issues: which model did you use?

Composer 2 Fast

GPT 5.4

Opus 4.6

For AI issues: add Request ID with privacy disabled

1174b4a6-9fa6-4fec-8b59-32d2161426c9

Additional Information

What we ruled out
Not Unix permissions: file is user-writable; terminal can write.
Not “wrong workspace”: workspace root is the worktree ‘featureX’, not parent repo (avoids parent .cursorignore pattern worktrees/* applying to this tree).
Not Ask mode: Cursor mode is Agent.
.cursorignore: Worktree .cursorignore does not list affected file or directory.

Does this stop you from using Cursor

Kind of - It cannot edit files inside the my worktrees.

Did some more troubleshooting with Opus 4.6 Agent, here is what it found:

The Cursor Read/StrReplace tools are both returning “Permission denied” for this file, but the OS-level permissions (-rw-rw-r--) are fine and shell commands can read and write to it without issue.

Even CLAUDE.md in the project root is blocked. This isn’t a .cursorignore issue at all - the Read tool can’t access any file in this workspace. Let me verify by testing a file outside the workspace.

That confirms it. The Read tool works fine outside the workspace (/tmp/) but returns “Permission denied” for every file inside this workspace. This is a Cursor-level workspace permission issue, not related to .cursorignore at all.

Findings:

  • .cursorignore (both at workspace and parent repo level) only blocks vendor dirs, and similar - nothing that would affect <file>

  • The Read and StrReplace tools are blocked for all files in this workspace

  • Files outside the workspace (e.g. /tmp/) work fine

  • Shell commands can read and write all workspace files without issue

  • OS-level permissions are normal (-rw-rw-r--, owned by mike:mike)

This looks like a Cursor workspace trust issue. The workspace may not be fully trusted, or there’s a bug with how Cursor handles git worktrees in terms of file access permissions. You might try:

  1. Reopening the workspace and ensuring it’s marked as trusted

  2. Checking Cursor settings for workspace trust (security.workspace.trust.enabled)

  3. Closing and reopening Cursor on this worktree

The 3 suggestion didn’t work.

Hey, thanks for the detailed report. This is a known issue: the Linux sandbox doesn’t handle git worktrees correctly. It blocks access to the .git pointer file (in a worktree it’s a file, not a folder), and because of that the agent tools (Read, StrReplace, Write) lose access to the whole workspace.

The same root cause is described here: Sandboxing blocks access to the .git file of a git worktree

For now, the only workaround is to disable the sandbox. The team is aware of the issue, but there’s no ETA for a fix yet.

Let me know if disabling the sandbox helps.

How do I disable the sandbox on linux? I do not see any sandbox options in the settings. (I think my mac has some settings but I don’t see any on linux.)

I tried searching and some recommended using the –no-sandbox cli flag, or setting Auto-Run to “Run Everything”.

Neither of these worked.

sorry for the noise - I didn’t tag you properly. How can I disable the sandbox? Everything I’ve tried has no affect. None of my worktrees appear to be usable at this point.

I used these directions for disabling the sandbox:

This issue still exists even with the sandbox disabled. (Unless “Auto-Run Mode” does not completely disable the sandbox. )

In case anyone else runs into this. I had the worktree/* in the cursor ignore to keep duplicates out of the index, open file, ect. It used to be that all your worktree files would show up in fuzzy search, but they no longer do so it looks like having these ignored is not necessary.

Removing the worktree from the cursorignore resolved the issue.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.