Skip to content

Keep .env files and keys out of the sandbox - #11

Merged
Kernel-Hunter merged 11 commits into
mainfrom
exclude-paths
Oct 30, 2026
Merged

Kernel-Hunter merged 11 commits into
mainfrom
exclude-paths

Conversation

@Kernel-Hunter

Copy link
Copy Markdown
Owner

Someone on Product Hunt pointed out that .env files end up in the agent's copy. They did: the clone took the whole folder, ignored files included.

This adds an exclude list per project. Files that match it are left out of both base/ and work/, so the agent never sees them and apply can never create, change or delete them.

  • Defaults: .env, .env.* (not .env.example, .env.sample, .env.template), .envrc, *.pem, *.key, *.p12, *.pfx, id_rsa, id_dsa, id_ecdsa, id_ed25519, .netrc. On for every project, including existing ones.
  • .gitignore syntax, with ** and !. Matching ignores case and Unicode normalization on every platform.
  • .mudroomignore at the project root adds patterns and can be committed. It can't let back in anything from your own list.
  • The list is saved in session.json when the session is created; diff and apply use that copy.
  • APFS clones and reflinks are pruned before session.json is written, so no sandbox starts on a clone that still has the files. Plain and Windows copies skip them while copying.
  • If the agent writes a file at an excluded path, diff shows it as X and apply skips it.
  • mudroom exclude list|add|remove|reset, a "Kept out of the sandbox" section in New Session, and a line at session start listing what was left out.

Tests: 29 new (265 total), covering matching, config, clonefile and plain copy, symlinks, read-only folders, apply refusing excluded paths, and old sessions without a list.

The Linux and Windows code paths (the readdir walker and the Windows copy loop) were not compiled locally, so CI is the first check for them.

ExcludeRules handles names at any depth, anchored paths, folder-only patterns, *, ?, [sets], ** and ! lines, compared without case and after Unicode normalization. ProjectConfig gets an exclude list that starts with the defaults (.env, .env.* but not the examples, .envrc, *.pem, *.key, *.p12, *.pfx, id_rsa and friends, .netrc). A .mudroomignore at the project root adds patterns as a separate list, so its ! lines can't take back the project's own.
Plain and Windows copies skip them. An APFS clone or reflink copies the whole folder, so the excluded entries are deleted from it before session.json is written; nothing can start a sandbox before then, and a failed delete drops the session. session.json records the patterns and what was left out.
The diff puts changes at excluded paths in their own list, which the stat and full output show with an X. Apply skips them with the pattern as the reason, also when handed a diff made without the session's rules. An agent edit to .mudroomignore is flagged like .envrc.
mudroom exclude list|add|remove|reset edits a project's list like the network commands do, and list shows what a new session would leave out. run, start and new print the files left out of the sandbox; diff, snapshots, hunks and review use the session's patterns.
Path matching is now a table over (segment, component), so a pattern full of ** can't hang session creation or the preview. Sets take POSIX classes ([:alpha:], [:digit:] and the rest); an unknown class is an error. .mudroomignore is opened without following links or blocking on a FIFO, must be a regular file of at most 1 MB, 1,000 patterns and 1,024 characters a line, and a file that breaks these rules or has a bad line stops session creation with the reason instead of being ignored.
The sheet passes its list to the session instead of relying on the saved config, stops if saving the settings fails, and shows why a project's .mudroomignore can't be used.
…eing created

Session start warns when git tracks a file that was left out, since the agent's repository sees it as deleted. Removing excluded entries clears macOS file flags (uchg) first, on the entry and its folder. create holds creating.lock until session.json exists, so a session still being cloned isn't listed as broken or discarded.
@Kernel-Hunter
Kernel-Hunter merged commit ba66b1c into main Oct 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant