Day 9 of 1060 minShell WalkerHands-on lab
Day 9: Writing a Team Policy for AI Coding Tools
Taught by Mr Elite Updated
By the end of today you can
- Turn a habit from days 2 to 8 into a rule that someone can check
- Write a one-page policy covering prompts, secrets, packages and agents
- Add one automated secret check to a git workflow or CI job
- Describe the first steps to take when a secret leaks into a prompt or repo
Warm-up
Answer from memory first, then tap to check. Recalling yesterday is what makes it stick.
Name two places a tool's text can reach the model when you connect an MCP server.
Tool names, descriptions and arguments all reach the model as text it may obey.
Why do you pin what you approved for a tool, and when do you re-review?
So a silent change cannot add new behaviour; re-review whenever the tool or its description changes.
A new developer joins your team on Monday. By lunch, their coding assistant has been given a pasted .env file, an unreviewed package has been installed, and an agent has been left running with full access to the home directory. Nobody did anything malicious. Nobody told them the rules, because the rules lived in the heads of two people.
Today we fix that. Over eight days you built habits: review output, protect inputs, limit power. Habits do not scale. A rule that is written down, short and checkable does. You will finish with a one-page policy and one automated check that enforces part of it.
From habit to rule
A habit is something you do because you remember. A rule is something a teammate can read, follow and be checked against. The difference is wording. 'Be careful with secrets' is a habit. 'Never paste values from .env files, key files or cloud consoles into a prompt' is a rule.
A good rule has three parts: an action, a boundary and a way to check. If you cannot say how someone would notice a breach of the rule, rewrite it until you can. Short rules also get read. Aim for one page, around ten rules, no more.
Let me show you the rewrite in practice. Start with the habit, ask what the boundary is, then ask who or what would spot a breach. The answer to that last question is your check. If the answer is 'nobody', the rule is still advice.
Habit: Check packages before installing them.
Action: Look up every new AI-suggested dependency on its registry page.
Boundary: Applies to any package not already in the lockfile.
Check: The pull request description links the registry page,
and a reviewer approves the lockfile diff.- Policy
- A short written set of rules a team agrees to follow.
- CI gate
- An automated check in your build pipeline that fails the build if a rule is broken.
- Least privilege
- Giving a tool only the access it needs for the task, nothing more.
Quick check
Which line is a checkable rule?
It names an action, a boundary and an automated way to verify it.
The four rule groups
Map the course onto four groups. Each rule below comes straight from a day you have already done, so you are collecting, not inventing. For each group I give the rule and then how someone would check it.
Notice that every group ends in a check. If you find a rule you cannot attach a check to, either make it smaller or move it to a separate guidance note. The policy page is for rules you will actually enforce.
Checks, gates and logs
Some rules need a human, such as judging whether a package looks trustworthy. Others a machine can check in seconds. Automate everything you can, because people skip steps when tired.
Three places to enforce: a pre-commit hook on the developer's machine, a CI job on every pull request, and branch protection that blocks merging until the job passes. The cheapest first gate is a secret scanner. The hook catches the mistake before it leaves the laptop. CI catches it when the hook was skipped. Branch protection makes sure nobody merges around the result.
Logging matters too. Keep a record of which agents ran, what tools they were approved for, and which commands needed approval, so you can reconstruct what happened later. A simple shared table with date, person, tool and action is enough to start. Decide who can read it, because a log of what people asked an assistant is itself sensitive.
Quick check
Why run the secret scan in CI as well as in a local hook?
A local hook depends on each person; the CI gate is the shared safety net.
Watch me do it: add a secret check
I will build a small automated check on your own machine, in a throwaway repo. We will use gitleaks, a free secret scanner. Nothing here touches anyone else's system. The key we plant is fake. Open a terminal before you start: Terminal on macOS, or your WSL or Linux shell.
mkdir policy-demo && cd policy-demo && git init
echo 'AWS_KEY=AKIAQ7XK2M5N3PWR4T6V' > config.txt
git add config.txt && git commit -m 'add config'gitleaks detect --source . --verbose
echo "exit code: $?"echo 'AWS_KEY=REDACTED' > config.txt
git commit -am 'remove key'
gitleaks detect --source . --verboseNext, the local hook. This file runs the scanner on staged changes every time you commit, and blocks the commit if it finds something. Create it inside the demo repo.
printf '#!/bin/shngitleaks protect --staged --verbosen' > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
echo 'TOKEN=AKIAQ7XK2M5N3PWR4T6V' > notes.txt
git add notes.txt && git commit -m 'try again'Now wire the same check into CI. This GitHub Actions file runs the scan on every pull request. Save it as .github/workflows/secrets.yml in a real project of your own when you are ready.
name: secret-scan
on: [pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2The last piece is branch protection. In your GitHub repository open Settings, then Branches, then add a rule for main. Tick 'Require status checks to pass before merging' and select secret-scan. Until you do this, a failing job is only a warning that anyone can ignore.
When a secret leaks: the response steps
Every policy needs a short incident section, written before the incident. When a key lands in a prompt or a repo, nobody thinks clearly, so give them a list. Put the owner's name and contact at the top of it.
Quick check
A key was committed, then deleted in the next commit. What do you do?
Git history keeps the old value, so the key must be treated as exposed.
Draft your one-page policy
Use this skeleton. Fill each heading with two or three rules in the action, boundary, check format. Keep sentences short. Someone should be able to read the page in three minutes.
AI CODING TOOLS POLICY
1. Scope: tools covered, who it applies to
2. Prompts and secrets: what never goes in
3. Packages: how a new dependency is approved
4. Agents and tools: permissions, approvals, MCP review
5. Pull requests: review checklist, CI gates
6. Logging: what is recorded and who can read it
7. If a secret leaks: steps, owner, time limit
8. Owner and review dateHere is how one filled-in section looks, so you can match the tone. Notice each line is one sentence, and the check is named.
4. Agents and tools
- Agents run in a container or project folder with no production
credentials. Check: environment review at setup.
- Delete, deploy and send actions need a human click. Check: approval
setting is on in the shared config file.
- New MCP tools are reviewed and pinned before use. Check: the tool
appears on the approved list with its reviewed version.Work through the headings in order and write quickly, then trim. After the lab below you will know which agent rule matters most, so come back and tighten section 4 with what you saw.
Your turn
AI Data Exfiltration
Before you write rules about agent tools, see why they are needed. In this lab an assistant with tools such as read_email and send_message does what the user asks without checking who is asking. It is a SecurityElites practice lab, so attack it freely there and nowhere else. Treat it as evidence for your policy.
What to try
What to notice
- The assistant trusts the request instead of checking authorisation
- Tool access with no per-user scope is the real weakness, not the wording of the prompt
- Your least privilege and approval rules would each have limited the damage
If it did not work
Writing vague rules such as 'use AI safely'
Rewrite each rule with an action, a boundary and a way to check it. If you cannot check it, it is advice, not policy.
Banning the tools outright
People will use them anyway, in secret. Give a safe route: approved tools, clear limits and quick approval.
Relying only on a local pre-commit hook
Add the same check to CI and protect the main branch so one person cannot skip it.
Cleaning a leaked secret but not rotating it
Always revoke and replace first. Deleting is tidying; rotation is the fix.
Recap
- A rule has an action, a boundary and a way to check it
- Group rules by prompts, packages, agents and review
- Automate what a machine can check, and enforce it in CI as well as locally
- Log who, what tool and when, without storing sensitive prompt contents
- Write the leak response before you need it: revoke, locate, clean, report
- One page, one owner and a review date keeps a policy alive
Cheat sheet
gitleaks detect --source .- Scan a repo and its history for secrets
gitleaks protect --staged- Scan only staged changes, used in a pre-commit hook
Exit code non-zero- Signals failure so CI blocks the merge
fetch-depth: 0- Makes CI fetch full history for scanning
Branch protection- Requires checks to pass before merging
Rotate, locate, clean, report- Order of response to a leaked secret
Action + boundary + check- Shape of a good rule
Before the next day
Mission: Your one-page policy and CI check
Finish the lab, then write a policy a real team could adopt, and add one automated check to a project of your own. This turns the course into something that outlasts your memory of it.
About 45 min
You are done when: A one-page ai-policy.md plus a working secret scan, shown by a failing run on a fake key and a passing run after removal.
Want more? Add a second gate that fails a pull request when package.json or requirements.txt changes without a reviewer approving the lockfile diff.
Quiz
4 questions. Your score is saved with your progress.
1. Which rule best fits the 'checkable' standard?
It states an action and a place where a reviewer can verify it.
2. The lab assistant read another user's email. Which policy rule addresses the root cause?
The flaw was unscoped tool access, so least privilege and approvals are the fix.
3. Why does the secret scanner exit with a non-zero code on a finding?
Pipelines decide pass or fail from exit codes.
4. A key appeared in a prompt to a hosted tool. What is the first action?
The key may already be copied, so make it useless before anything else.
Finish the day
Mark the day complete to save your progress.
Next: Day 10 is the capstone. You will audit a project built with AI help, using every check from this course, and deliver findings plus a hardened configuration. Today's policy becomes your standard to audit against.
Your notes
Private to this device. Write what you want to remember from today.