Kamran Imam All free guides
Workflows

Automation Loop Setup: Let AI Run on Your Real Files — Safely

A free guide by Kamran ImamInstagram · TikTok · YouTube

Running an AI agent against real files is one of the highest-leverage things you can do — and one of the easiest ways to make an irreversible mess if you skip the setup. These are the three guardrails I put in place before any agent touches a single file. Take fifteen minutes to do this once; it'll save you from a bad day.

Guardrail 1 — Least privilege: scope the agent to one sandbox folder

The default instinct is to give the agent access to everything so it can “just work.” Resist that. The more surface area it has, the more places a mistake can land.

Instead, create a single dedicated folder — call it ai-sandbox, agent-work, or whatever you’ll remember — and make that the only directory the agent is allowed to touch. Anything outside it is off limits.

In practice:

This won’t stop a determined mistake, but it dramatically shrinks the blast radius of an accidental one.

System prompt addition: You may only read and write files inside /projects/ai-sandbox/. Do not access, modify, or reference any file outside that directory. If a task requires a file that isn't there, ask me to place it in the sandbox first.

Guardrail 2 — Make every change reversible before the agent starts

Agents move fast. If you don’t have a recovery path, you’re one bad run away from losing work. Set up your undo layer before you start, not after something goes wrong.

Pick one of these depending on what you’re working with:

# Commit the clean state before each agent session cd /projects/ai-sandbox git add -A git commit -m "pre-agent snapshot $(date +%Y-%m-%d_%H:%M)" # After the run, review what changed git diff HEAD~1 # Roll back everything if needed git checkout HEAD~1 -- .

The goal is that no matter what the agent does, you can get back to where you started in under a minute.

Guardrail 3 — Approve on write: the agent proposes, you decide

This is the highest-leverage guardrail because it stops problems before they happen rather than cleaning them up after. The idea: configure the agent so it shows you what it plans to change and waits for your explicit sign-off before writing anything.

How you implement this depends on your setup:

System prompt addition: Before writing, creating, or deleting any file, describe exactly what you plan to do in plain language: which file, what change, and why. Then stop and wait for me to reply "approved" before taking any action. Do not write anything without explicit approval.

Yes, this adds a confirmation step per write. That’s the point. Once you trust the agent’s behavior on a given task, you can relax this constraint for that specific workflow — but start with it on.

Putting it together: the pre-flight checklist

Before you kick off any agent loop against real files, run through these three checks:

  1. Sandbox in place? Agent is scoped to one folder and nothing outside it.
  2. Snapshot taken? Git commit, working copy, or version history enabled — clean state is recorded.
  3. Approve-on-write active? Agent will describe changes and wait for your go-ahead before touching anything.

All three green? Run the agent. None of this slows the work down in a meaningful way once it’s set up — it just means you’re in control of what actually lands on disk.

Common mistakes

Found this useful? Follow along for new guides.

New breakdowns drop every week across TikTok, Instagram, and YouTube.

← All free guides