Letting an AI agent run my homelab: guardrails that actually work
How I let a coding agent operate a small Kubernetes homelab through GitOps, without ever showing it a secret, and the written rules that keep it from doing anything I would regret.
On this page
For a few weeks now an AI coding agent has done most of the routine work in my homelab. It upgrades charts, writes alert rules, debugs failing jobs, and fixes the occasional broken deployment in the middle of the night. That sounds reckless, and it would be if the agent simply got a root shell and a hopeful prompt.
What made it work was not a better model. It was a set of boring, explicit guardrails. This post describes them, because I think they carry over to any setup where an agent touches real infrastructure.
1. Git is the only way to change the cluster
The cluster runs on GitOps. Argo CD continuously reconciles the cluster against a Git repository, so the desired state of every application lives in YAML in that repo.
The agent's main rule is simple:
Changes to the cluster happen through commits to the GitOps repo, never through ad-hoc
kubectl apply.
Imperative commands are allowed for diagnosis (get, describe, logs) and for a short list of one-off operations. Everything else is a commit, which gives me three things for free:
- An audit trail. Every change has a diff and a commit message that names the task it belongs to.
- Easy rollback.
git revertand Argo CD does the rest. - Review after the fact. I read the log in the morning instead of watching a terminal at night.
2. The agent never sees a secret
This is the rule I care most about. The agent may handle encrypted secrets but never plaintext values:
- Secrets live in the repo only as Sealed Secrets, encrypted with the cluster's public key.
- When a new secret is needed, the agent does not ask me for the value. It gives me a one-line command with placeholders, and I fill them in and run it in my own terminal:
kubectl create secret generic app-db --dry-run=client --from-literal=password='<PASSWORD>' -o yaml | kubeseal --format yaml > app-db.sealedsecret.yaml
- The agent only checks secrets by key names and value lengths, never by content:
kubectl get secret app-db -o json | jq '.data | map_values(@base64d | length)'
Since there is nothing to leak, a prompt-injection attack or a careless log line cannot expose a password. The worst case is an encrypted blob that only the cluster can open.
3. Rules live in ADRs, not in the prompt
At first I put rules into the agent's instruction file. That turned into a long, contradictory wall of text, so I moved them into Architecture Decision Records.
Each ADR has a short "Rules" section with numbered, testable statements:
## Rules
- **R-SEC-1** (MUST): Secrets are stored in the repo only as SealedSecrets.
- **R-SEC-2** (MUST NOT): Print, log or commit secret values in plaintext.
- **R-SEC-3** (MUST NOT): Agents read unsealed secret values; checks use key names and lengths only.
A small script collects all rules from accepted ADRs into one generated file, and the agent loads that file at startup. This has some nice properties:
- Every rule has a reason, because the ADR around it explains the decision.
- Rules have IDs, so the agent can cite them ("not doing this, see R-OPS-4") and I can change one rule without rewriting a prompt.
- Conflicts become visible. Two ADRs that disagree are much easier to spot than two sentences buried in a long prompt.
4. Two explicit lists: "just do it" and "ask first"
The biggest source of friction was the grey zone. An agent that asks before every pod restart is useless, and one that never asks will eventually delete something important. The fix was to write both lists down.
Allowed without asking (but reported in the summary):
- delete completed or failed Jobs and Pods
- trigger an Argo CD refresh or sync
- start a test run of a CronJob (
kubectl create job --from=cronjob/...) rollout restartof stateless deployments- commit and push to the lab repositories, including image pins
- silence a known false alarm, as long as the manifest says why
Only with explicit approval in the current conversation:
- deleting or overwriting data, volumes or backups
- restoring into a production database or migrating production data
- deleting a secret that a workload still uses
- anything that forces a node reboot or an outage
- anything that costs money or communicates on my behalf (orders, emails, social posts, public DNS)
Approval does not carry over. "Yes, restore the database" on Tuesday does not cover another restore on Friday.
The agent's own tool permissions are a second, independent layer. Even when the agent thinks an action is fine, the harness can still block it, and when that happens the agent hands me the exact command instead of looking for a workaround.
5. One place for tasks
The agent keeps no private to-do list. All work lives in a plain-text task board (Backlog.md) inside a Git repo. Every task has acceptance criteria, an assignee (me or the agent) and implementation notes.
When the agent finishes something, it ticks off the acceptance criteria and appends notes with numbers: what it measured, what changed, and what is still open. When it works overnight, it adds a "night note" task that I read over coffee.
Because the board is Git-backed, it has the same audit trail as everything else.
6. Prove it, don't claim it
My last rule: "done" means verified. After a change the agent has to show evidence:
- the Argo CD app is
SyncedandHealthy - the rollout finished
- the job ran and its logs say what we expected
- for UI changes, screenshots at desktop and phone width, which it actually looks at
If a check fails, the agent says so with the output instead of calling the task done. This rule alone removed most of the "it should work now" moments.
What still goes wrong
The agent is not perfect, and the guardrails are designed with that in mind:
- It sometimes misreads timing, for example by expecting a weekday job on a Saturday. Writing the expected time and evidence into the task makes this visible quickly.
- It can be confidently wrong about a root cause. The "evidence before done" rule catches most of these.
- It needs good context. A short, current overview page (cluster facts, conventions, where things live) helps more than anything else.
Takeaways
If you want to try this yourself:
- Put the cluster on GitOps first. It makes everything an agent does reviewable and revertible.
- Never give the agent plaintext secrets. Use placeholders and let a human seal the values.
- Write rules as numbered, reasoned decisions, not as a growing prompt.
- Make the "ask first" list explicit, and keep it short.
- Require evidence for "done".
None of this is specific to one model or tool. It is the same discipline you would want from a new colleague with production access, just written down more strictly.