The report said a developer asked an agent to clear a cache and ended up with the contents of a drive gone. That night I opened my own build-cleanup shell script instead of closing the tab.
As an indie developer, I clear build leftovers several times a week. One line in that script, if its variable ever came through empty, could have pointed at a root directory. The report was about an agent, but my stomach dropped over an old script of mine.
What I want to say first: narrowing how far a delete can reach matters more than deciding whether to switch approvals off. Below is a small Python checkpoint, the four holes I found in my first version when I attacked it again in November, and the line I draw between what I hand over and what I don't.
What was reported, and what I won't claim
In early December 2025, several tech outlets covered a user's report that a Google Antigravity agent, asked to clear a project cache, wiped the contents of their Windows D: drive. What I have read is the headlines and summaries of that coverage.
Whether the cause was a vague instruction, path resolution, or an approval setting, I can't tell from what is public. So please read what follows not as a reproduction of that case, but as a precaution against the same kind of accident in your own setup. The kind is simple: the delete reached further than the person who asked imagined.
Narrow the reach first, polish the request second
My first instinct was to fix the prompt. I added "only the build folder of this project" and then more reminders. The results were poor, because a reminder only works if the reader honors it.
I do it the other way round now. I don't leave correctness to attention or polite wording. A machine checks the scope at the one point just before the delete runs. The checks are few:
- The target is not an empty string (this catches an unexpanded variable)
- Once resolved to a real path, the target sits inside the project
- The target is not the project root itself
- The target is not shallow, like
/or/Users/name - Symbolic links are not followed
- Directories that contain
.gitare never removed
Every one of these looks obvious in hindsight. That is exactly why they slip when left to human eyes.
Four holes in my first version
When I first published this in October, the checkpoint (call it v1) passed all eight bad targets I threw at it. Rereading it in November, I realized I had only tested the bad targets I could think of. So this time I changed the situation the agent might be in instead.
Setup: Ubuntu 22.04, Python 3.10.12. A fake home me holds proj (with build/cache and a nested repo at packages/lib/.git), plus outside (a 5 MB file) and Documents outside the project. Paths below are shortened.
| Situation | v1 result | Why it's a problem |
|---|---|---|
Shell still sitting in the home folder, target Documents | planned: /…/me/Documents (2 bytes), exit 0 | --root defaulted to the current directory, so from home, all of home counted as "inside the project". Running from / passed too |
packages (its lib/.git is one level down) | planned, exit 0 | v1 only looked for .git directly under the target. A nested repo walked straight through |
dist "" with --apply | dist deleted, then the empty string refused, exit 1 | It checked and deleted one target at a time, so by the time a refusal appeared, earlier targets were already gone |
build (contains a link to the 5 MB file outside) | (5,000,002 bytes) | Only the link itself is removed; the outside file survives. The planned size misleads the person reviewing it |
The first row is the one that made me sweat. I don't watch where the agent's terminal happens to be opened every time. I had tied the checkpoint's scope to wherever the caller was standing, which is structurally the same mistake as writing reminders into the prompt.
I also found that a nonexistent path produced a FileNotFoundError traceback rather than a one-line refusal. The exit code was still 1, but a long traceback leaves room for an agent to read it as "some other problem".
Checkpoint v2: explicit root, check everything before deleting anything
Five fixes. The root must come from --root or the SAFE_RM_ROOT environment variable; the current directory is never used, and a root at or above home is refused. .git is searched for through the whole target without following links. With --apply, nothing is deleted until every target passes. Sizes are counted with lstat, so links count as links. And to match the table further down, anything inside a synced folder (Dropbox and the like) is refused unless you pass --allow-synced.
Save it as safe_rm.py somewhere outside the project, such as ~/bin. Keeping it outside the project is a small detail that matters. If it lives where the agent can edit, the checkpoint itself can be rewritten.
#!/usr/bin/env python3
"""A checkpoint in front of deletes, v2. Dry-run by default; with --apply it deletes only after every target passes."""
from __future__ import annotations
import argparse
import os
import shutil
import sys
from pathlib import Path
MIN_DEPTH = 3 # refuse /Users/name and anything shallower; root must be deeper
SYNCED = {"Dropbox", "CloudStorage", "Mobile Documents", "OneDrive", "Google Drive"}
class Refused(Exception):
pass
def load_root(arg: str | None) -> Path:
raw = arg or os.environ.get("SAFE_RM_ROOT", "")
if not raw:
raise Refused("no root given (use --root or SAFE_RM_ROOT; cwd is never used)")
root = Path(raw).expanduser().resolve(strict=True)
if len(root.parts) <= MIN_DEPTH + 1 or root == Path.home():
raise Refused(f"root is too shallow: {root}")
return root
def find_git(real: Path) -> Path | None:
if (real / ".git").exists():
return real / ".git"
for d, dirs, files in os.walk(real, followlinks=False):
if ".git" in dirs or ".git" in files:
return Path(d) / ".git"
return None
def size_of(real: Path) -> int:
if not real.is_dir():
return real.lstat().st_size
total = 0
for d, _, files in os.walk(real, followlinks=False):
total += sum(os.lstat(os.path.join(d, f)).st_size for f in files)
return total
def check(target: str, root: Path, allow_synced: bool) -> Path:
if not target.strip():
raise Refused("empty target (a variable may not have expanded)")
p = Path(target).expanduser()
if p.is_symlink():
raise Refused(f"will not follow a symbolic link: {p}")
try:
real = p.resolve(strict=True)
except FileNotFoundError:
raise Refused(f"does not exist: {p}")
if len(real.parts) <= MIN_DEPTH:
raise Refused(f"too shallow: {real}")
if real == root or root not in real.parents:
raise Refused(f"outside root, or root itself: {real}")
if not allow_synced and SYNCED & set(real.parts):
raise Refused(f"inside a synced folder (needs --allow-synced): {real}")
g = find_git(real) if real.is_dir() else None
if g:
raise Refused(f"contains .git, not deleting: {g}")
return real
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("targets", nargs="*")
ap.add_argument("--root")
ap.add_argument("--apply", action="store_true")
ap.add_argument("--allow-synced", action="store_true")
a = ap.parse_args()
try:
root = load_root(a.root)
if not a.targets:
raise Refused("no targets")
plan = [check(t, root, a.allow_synced) for t in a.targets] # check every target first
except (Refused, FileNotFoundError) as e:
print(f"refused: {e}", file=sys.stderr)
return 1
for real in plan:
print(f"{'deleted' if a.apply else 'planned'}: {real} ({size_of(real):,} bytes)")
if a.apply:
for real in plan:
shutil.rmtree(real) if real.is_dir() and not real.is_symlink() else real.unlink()
return 0
if __name__ == "__main__":
sys.exit(main())Four notes on why it's written this way:
- Nothing is deleted without
--apply, so the first command an agent runs is always "show the plan". resolve(strict=True)turns..and links in the middle of a path into the real location before the inside-root test. A plain string prefix check would confuse/projwith/proj-old.from __future__ import annotationskeeps thestr | Nonehints from being evaluated on Pythons older than 3.10, since the python3 that ships with macOS can be older. I have only run it on 3.10 myself.- Every failure is a single
refused: …line plus exit 1, so an agent has nothing to misread.
What v2 did on the same fake home
| Input | v2 result |
|---|---|
Documents, no root, shell in home | refused: no root given (use --root or SAFE_RM_ROOT; cwd is never used) |
--root set to home itself, or /tmp | refused: root is too shallow |
packages (nested lib/.git) | refused: contains .git, not deleting: /…/packages/lib/.git |
dist "" with --apply | refused on the empty string; dist still there |
build with the outside link | planned: /…/proj/build (68 bytes); after --apply the 5 MB file outside is untouched |
nothere | refused: does not exist: nothere |
../outside | refused: outside root, or root itself |
Dropbox/app/build | refused: inside a synced folder (needs --allow-synced); with the flag, the plan is shown |
The 68 bytes are the 2-byte real file plus the two links themselves. Now the number on the plan is close to what will actually be freed, and the person reading it before --apply is finally deciding on the right facts.
Troubleshooting by symptom
| Symptom | Likely cause | How to check | Fix |
|---|---|---|---|
A build you meant to clear is refused as "outside root" | SAFE_RM_ROOT still holds another project's path | Compare echo "$SAFE_RM_ROOT" with the path in the refusal | Pass --root on every call; use the variable only in a session that touches one project |
vendor or similar is refused for containing .git | A submodule or a dependency cloned straight from Git lives inside | Read the .git path printed in the refusal | Remove that folder by hand after looking inside. Don't loosen the checkpoint |
The plan appears, then the agent reruns it with --apply on its own | Your auto-allowed commands include the --apply form | Look at how safe_rm.py appears in your editor's or agent's permission settings | Allow only the argument-only (dry-run) form; route --apply through review every time |
| Something else got deleted even though you use the checkpoint | The agent ran rm or rmdir directly | Check terminal history and the agent's run log | Put direct delete commands on the deny side, so deletes go through the checkpoint only |
| The agent reports success after a refusal | It read part of the output and ignored the exit code | Run the same command yourself and check echo $? | Write "check the exit code before reporting" into both the instructions and the steps |
Where to stop it: a comparison, and how I choose
| Measure | Catches | Misses | Best for |
|---|---|---|---|
rm -i / rm -I | A human typing too fast | An agent piping in y, or choosing another command | Deleting by hand |
git clean -n (preview only) | The set of untracked files in a repo | Anything outside the repo; adding -d or -x at run time after previewing without them | Cleaning inside one repo |
| Agent-side allow/deny settings | Whether a given command may run at all | What a variable expands to, or what happens inside an allowed script | Deciding which commands may be typed |
| Terminal sandbox | Writes outside the workspace | Over-deleting inside the workspace | Always, where available |
| A delete checkpoint (this article) | Empty variables, shallow paths, escaping the root, nested repos, synced folders | Deletes that bypass it | Handing cleanup to an agent |
My rule fits in one sentence: agent settings decide which commands may run; the checkpoint decides how far those commands can reach. Settings alone can't see how wide a command spreads, and a checkpoint alone can't see deletes that go around it, so I layer the two.
Three common misreadings
"Showing a dry-run makes it safe." v1's plan said 5,000,002 bytes for a folder where only 2 bytes would actually go. The plan is what a human decides on; if its numbers are off, no amount of care in reading it fixes the decision.
"Calling resolve() takes care of links." resolve() untangles .. and links in the middle of a path. When the target itself is a link, both v1 and v2 refuse it earlier with is_symlink(). For links inside a folder, Python's shutil.rmtree removes the link rather than descending into it; on my machine the 5 MB file outside was intact after deleting a build that linked to it.
"The agent is surely working in the project folder." I leaned on exactly this when I wrote v1. Where the terminal was opened, a cd halfway through, a session left pointing at another folder: the current directory moves for many reasons. That's why v2 stopped guessing the root from it at all.
What I hand over without approval, and what I don't
A checkpoint doesn't replace drawing the line on what to delegate. Here is how I split it.
| Task | Without approval? | Why |
|---|---|---|
| Regenerating build output | Yes | The same steps bring it back if it's lost |
Deleting via safe_rm.py (dry-run) | Yes | It only prints the plan; nothing changes |
safe_rm.py --apply | After I look | A person reads the printed plan once |
| Deletes involving paths outside the project | No | A person checks first whether it can be undone |
| Deletes under a synced folder (Dropbox, etc.) | No | The deletion propagates to other devices |
The synced-folder row comes from my own setup. My working files live in Dropbox, and anything deleted there, without a local backup, means digging through version history. It's recoverable, but I'd rather not be doing that at midnight. Making v2 refuse synced folders by default moved that row from "be careful" to "the machine stops it".
A second safety net for when the checkpoint isn't in the path
Even with deletes narrowed, I keep a separate way back. Before any large task I don't skip two things:
- Commit the working directory once, so its state is pinned, untracked files included
- Keep anything outside the project out of the agent's working directory in the first place
Setting names and where they live change between versions, so I won't walk through screens here. As of November 2026, Antigravity's official docs have pages for Agent permissions and the Terminal sandbox. On the day you change settings, I'd keep those open and check the current names there.
The next thing you'll run into
Right after adding a checkpoint, the usual question is which commands the agent should never type directly. I wrote up how I pick the first deny-list entries by counting my own shell history in Start your Deny list from your own shell history.
If you're torn about loosening approvals, when "Always Proceed" still asks: loosen by command kind is a reasonable starting draft for drawing that line per command type.
And if you run agents unattended overnight, guarding against an unattended agent rewriting its own settings covers checking from the outside that the checkpoint and its settings haven't been changed.
Start with one line
The one thing I'd suggest today: open your delete script or checkpoint and check where the value that sets its scope comes from. The current directory, an environment variable, or an argument. Just checking that made me sweat over my own October checkpoint.
People polish the request, the machine narrows the reach, and a person states the boundary explicitly. That split is the one I keep even on tired days.