[BUG] Sandbox mode breaks zsh heredocs - TMPPREFIX not set to sandbox-allowed path
Resolved 💬 2 comments Opened Jan 13, 2026 by soleilcot Closed Feb 27, 2026
Description
When sandbox mode is enabled on macOS with zsh, heredocs fail with:
(eval):1: can't create temp file for here document: operation not permitted
Root Cause
Claude Code sets TMPDIR=/tmp/claude for sandbox mode, but zsh uses TMPPREFIX (not TMPDIR) for its internal temporary files, including heredocs.
Per the official zsh documentation:
TMPPREFIX: A pathname prefix which the shell will use for all temporary files. The default is '/tmp/zsh'.
When a heredoc is processed, zsh creates temp files like /tmp/zshXXXXXX, which is outside the sandbox-allowed /tmp/claude/ directory, causing the permission error.
Evidence
# In sandbox mode:
$ echo "TMPPREFIX: $TMPPREFIX"
TMPPREFIX: /tmp/zsh
$ echo "TMPDIR: $TMPDIR"
TMPDIR: /tmp/claude
$ cat << 'EOF'
test
EOF
# ERROR: can't create temp file for here document: operation not permitted
Proposed Fix
Add TMPPREFIX to the sandbox environment setup alongside TMPDIR:
export TMPDIR=/tmp/claude
export TMPPREFIX=/tmp/claude/zsh # <-- Missing, needed for zsh
This aligns with the recommended fix for similar TMPPREFIX issues: export TMPPREFIX="$TMPDIR/zsh"
Workaround
Users can add this to their settings.json:
{
"env": {
"TMPPREFIX": "/tmp/claude/zsh"
}
}
Environment
- OS: macOS (Darwin 24.3.0)
- Shell: zsh
- Claude Code: Latest version with sandbox enabled
Related Issues
- #13583 - Sandbox bypass security issue (symptoms include heredoc failures)
- #11480 - Sandbox cwd tracking writes to blocked
/tmp/path
References
- zsh Parameters Documentation - Official TMPPREFIX documentation
- zsh heredoc temp file explanation - Detailed writeup of this issue class
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗