A read-only Gemma 4 agent on Ollama that explains what fills a Mac's disk
- Hardware
- Apple Silicon Mac with 24 GB of RAM, macOS 15, Python 3.14
- Models & engines
- gemma4 (5 GB) in Ollama
- Key gotcha
- The model was good at picking folders but not at judging them: it labelled ~/.vscode as SAFE to clear even though it holds installed extensions, which is why no tool can delete
What they built
MediBlackSand, a sysadmin of about a decade who is learning Python and agents by building small tools, wrote Disk Detective: a Python agent that uses Gemma 4 on Ollama to explain what is filling his Mac's disk. Everything runs locally, with no API keys, no cloud and no pip install, just Python's standard library and Ollama.
Because the task touches private files, the post focuses on proving the agent can only read. His rule: the prompt asks, the code limits, and the OS enforces.
Setup
- Apple Silicon Mac with 24 GB of RAM, macOS 15, Python 3.14
- gemma4 (5 GB) in Ollama
- Disk Detective: one Python file of about 280 lines, standard library only
- Run as `python3 disk_detective.py` for the home folder or with a folder path such as `~/Desktop`
How it works
- The model gets three tools: disk_overview (shutil.disk_usage), largest_children (runs `du -d 1 -k`) and largest_files (os.walk + os.lstat); none can change anything on disk
- An agent loop of about 25 lines calls the model, checks each requested tool against an allow-list, runs it, and sends results or errors back; the model never runs code itself
- A step budget (max_steps = 10) is a ceiling, not a target
- Every model-supplied path goes through safe_path(), which resolves the path before checking it is inside the home folder, so `~/../../etc` and outside symlinks are refused
- The only write is the report, to a filename the user picks with --out
Results & numbers
- A typical run on his home folder took 5 tool calls (overview, ~, ~/Library, ~/Library/Caches, ~/Downloads), finished in about two minutes and wrote a Markdown report
- Gemma stopped after 5 of 10 allowed steps on its own
- Inside the sandbox, `touch ~/Desktop/should-fail.txt` failed with "Operation not permitted", while the agent ran normally and wrote its report
Gotchas
- The model was good at picking folders but not at judging them: it labelled ~/.vscode as SAFE to clear even though it holds installed extensions, which is why no tool can delete
- A system prompt saying "you can only look" is a request, not a guarantee
- `du` is called with a list of arguments and no shell=True, so a path like `"; rm -rf ~"` arrives as an odd folder name, not a command
- Resolve paths before checking them; checking first lets `..` and symlinks through
- Apple marks sandbox-exec as deprecated, but he says it still works on current macOS (tested on macOS 26 too); on Linux he points to a read-only bind mount or bwrap
“The prompt asks. The code limits. The OS enforces.”— MediBlackSand
Do it yourself
- Install Ollama and pull a Gemma 4 model
- Write a small tool-calling loop in Python that only exposes read-only functions and rejects unknown tool names
- Pass every path the model gives through a resolve-then-check helper that keeps it inside your home folder
- Audit the file with grep for open(, write, remove, unlink, rmtree, rename, mkdir, chmod, shell=True, eval(, exec(, subprocess and os.system; he expects exactly three hits
- Save a four-line Seatbelt profile that denies file writes under HOME except the report file, then run the agent with sandbox-exec
- Test it by trying a write inside the sandbox and confirming "Operation not permitted"
(version 1)
(allow default)
(deny file-write* (subpath (param "HOME")))
(allow file-write* (literal (param "OUT")))
# run:
OUT="$PWD/report.md"
sandbox-exec -D HOME="$HOME" -D OUT="$OUT" -f readonly.sb python3 disk_detective.py --out "$OUT"Similar setups
Local AI: a one-click Windows app that picks a model for your PC and sets up Ollama for friends
Tired of setting up local LLMs for friends, a developer built a free MIT-licensed Windows app that detects your GPU and RAM, installs Ollama without admin rights, pulls a fitting model and opens a private chat.
Haunted Inbox: a local Gemma 4 E2B finds the forgotten accounts in 12 years of email
Niraj Khetre built Haunted Inbox, which reads only email envelopes on his laptop, has Gemma 4 E2B in Ollama spot sign-up accounts, and lets plain code report breaches, saved cards and delete links.
Legacy Code Necromancer: a local Gemma 3 audit for old repos
Waleed Shamhan built a pure-Python CLI that scrubs secrets from old code, sends it only to a local Gemma 3 in Ollama for an audit, and keeps every raw reply so a human can check each finding.
Couch Commander: an offline voice remote for YouTube that understands Pidgin
Benny built Couch Commander, which chains openWakeWord, Whisper and Gemma 4 E2B in Ollama on a Mac so spoken commands in English or Nigerian Pidgin control YouTube in Chrome with no internet.