@@ -271,9 +271,16 @@ pub enum SandboxPolicy {
271271 /// writable roots on UNIX. Defaults to `false`.
272272 #[ serde( default ) ]
273273 exclude_slash_tmp : bool ,
274+
275+ /// When true, do not protect the top-level `.git` folder under a writable root.
276+ /// Defaults to true to match historical behavior that permits Git writes.
277+ #[ serde( default = "default_true_bool" ) ]
278+ allow_git_writes : bool ,
274279 } ,
275280}
276281
282+ const fn default_true_bool ( ) -> bool { true }
283+
277284/// A writable root path accompanied by a list of subpaths that should remain
278285/// read‑only even when the root is writable. This is primarily used to ensure
279286/// top‑level VCS metadata directories (e.g. `.git`) under a writable root are
@@ -328,6 +335,7 @@ impl SandboxPolicy {
328335 network_access : false ,
329336 exclude_tmpdir_env_var : false ,
330337 exclude_slash_tmp : false ,
338+ allow_git_writes : true ,
331339 }
332340 }
333341
@@ -363,6 +371,7 @@ impl SandboxPolicy {
363371 writable_roots,
364372 exclude_tmpdir_env_var,
365373 exclude_slash_tmp,
374+ allow_git_writes,
366375 network_access : _,
367376 } => {
368377 // Start from explicitly configured writable roots.
@@ -400,9 +409,11 @@ impl SandboxPolicy {
400409 . into_iter ( )
401410 . map ( |writable_root| {
402411 let mut subpaths = Vec :: new ( ) ;
403- let top_level_git = writable_root. join ( ".git" ) ;
404- if top_level_git. is_dir ( ) {
405- subpaths. push ( top_level_git) ;
412+ if !allow_git_writes {
413+ let top_level_git = writable_root. join ( ".git" ) ;
414+ if top_level_git. is_dir ( ) {
415+ subpaths. push ( top_level_git) ;
416+ }
406417 }
407418 WritableRoot {
408419 root : writable_root,
0 commit comments