Tegoby Attention SpanBlogBook a demo

Stop your agent deleting your files

To stop an AI agent deleting files outside your project, limit its writes below the agent, not in its command checks. A Tego contract names the folders the agent may write in fs.write, and the Linux kernel refuses every other write, delete, rename or link, at every level, whichever program or script makes it. It does not protect what is inside the folders you allow, so keep those under version control.

For the bigger picture, read AI agent security on Linux. We make Tego; claims about it link its docs and repository.

Why do aliases and command checks fail?

They read the command text, and a delete does not have to appear in it. A shell alias for rm applies only to the shell that loaded it. A permission rule matches what the agent typed: Claude Code's docs say a Bash rule "doesn't match the same program invoked in a different form", so a deny or ask rule is not "a security boundary around the program" (Configure permissions). A delete inside a script, a cleanup trap, a Python shutil.rmtree or a find -delete all reach the files without the words a check looks for.

That is what a user reports in a Claude Code issue: a cleanup trap in a test script the agent wrote ran rm -rf on their WSL2 home folder (#88462). The command the check saw was a bash command; the delete ran later, from the script. The teardown walks through it.

Claude Code's permissions page points to its sandbox for filesystem enforcement that does not depend on the command text. On Linux it uses bubblewrap, and by default sandboxed commands write only to the working directory, a per-user temp folder and folders you add (Sandboxing). If you run Claude Code, turn it on. It covers the shell commands Claude Code runs and their child processes; a Tego contract holds the whole agent process, whichever agent it is.

How does a contract scope writes?

Name each folder the agent may write. Everything else is refused:

YAML
extends: [tego/repo-only-writes]
fs:
  write: ["./src/", "./tests/"]

In Tego's terms, "A write here means changing a file's contents and making, removing, renaming or linking a file or folder" (Write a Tego contract). So rm -rf ~ from a script fails with a permission error on every file outside ./src/ and ./tests/. More from the same page:

  • Beneath every write folder, Tego still refuses git's hooks and config and shell startup files such as .bashrc.
  • /tmp is refused; give tools a temporary folder under one of your write folders.
  • ./ is refused while the contract file sits in it. Keep the contract outside the project, and then ./ makes the whole project writable.

The refusal goes into the run's hash-chained record, which lives outside the folders the agent may write. With no fs: section at all, every write is refused.

What about deletes inside the project?

They are allowed, because the folder is writable. Tego cannot tell a cleanup you wanted from one you did not. Three ways to narrow it:

  • Write only where the task writes. ./src/ and ./tests/ rather than ./.
  • Refuse the command too. An exec.deny entry for rm -rf also matches -fr, -r -f and --recursive --force, but not plain rm -r, so Tego's own demo denies rm -r. At Basic, Tego's supervisor checks command rules on its copy of the arguments, best effort against a hostile racing thread (README).
  • Hold the folder for a person. An fs.ask folder, kept outside every fs.write entry, holds each write there, deletes included, until you answer with tego approve or tego deny or in the dashboard; no answer in time is a refusal (Write a Tego contract).

And commit often: git is still your undo. Tego refuses writes, but it does not restore files.

What does this not stop?

  • Deletes inside an allowed folder, as above.
  • Effects in other systems. An API call to a host you allowed can delete a database or a bucket; the contract sees a connection, not what it does. An agent swapped the Terraform state file, then ran destroy on production shows a delete that reached AWS through Terraform, a network call no folder rule sees.
  • File modes and attributes. chmod is not refused at any level, and at Basic neither is a change of owner, extended attributes or timestamps.

Security and known limits has the full list. For the read side, see Keep AI agents away from your SSH keys and .env files.

Sources (6 links)

Read on 6 November 2026.