From 18c18ec3a8b21df9000699c3c7674698c8ff5ba9 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Fri, 13 Feb 2026 13:53:19 -0600 Subject: [PATCH] fix: avoid creating directory at file path in allowRead bwrap mounts intermediaryDirs() was called with the full path including the leaf component, causing --dir to be emitted for files like ~/.npmrc. This created a directory at that path, making the subsequent --ro-bind fail with "Can't create file at ...: Is a directory". Now checks isDirectory() and uses filepath.Dir() for file paths so intermediary dirs are only created up to the parent. --- internal/sandbox/linux.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/sandbox/linux.go b/internal/sandbox/linux.go index 7f04fda..831db51 100644 --- a/internal/sandbox/linux.go +++ b/internal/sandbox/linux.go @@ -519,8 +519,14 @@ func buildDenyByDefaultMounts(cfg *config.Config, cwd string, debug bool) []stri if fileExists(p) && canMountOver(p) && !strings.HasPrefix(p, "/dev/") && !strings.HasPrefix(p, "/proc/") && !boundPaths[p] { boundPaths[p] = true - // Create intermediary dirs if needed - for _, dir := range intermediaryDirs("/", p) { + // Create intermediary dirs if needed. + // For files, only create dirs up to the parent to avoid + // creating a directory at the file's path. + dirTarget := p + if !isDirectory(p) { + dirTarget = filepath.Dir(p) + } + for _, dir := range intermediaryDirs("/", dirTarget) { if !isSystemMountPoint(dir) { args = append(args, "--dir", dir) } @@ -533,7 +539,11 @@ func buildDenyByDefaultMounts(cfg *config.Config, cwd string, debug bool) []stri if !ContainsGlobChars(normalized) && fileExists(normalized) && canMountOver(normalized) && !strings.HasPrefix(normalized, "/dev/") && !strings.HasPrefix(normalized, "/proc/") && !boundPaths[normalized] { boundPaths[normalized] = true - for _, dir := range intermediaryDirs("/", normalized) { + dirTarget := normalized + if !isDirectory(normalized) { + dirTarget = filepath.Dir(normalized) + } + for _, dir := range intermediaryDirs("/", dirTarget) { if !isSystemMountPoint(dir) { args = append(args, "--dir", dir) }