Give your agent only what it used
Least privilege for an AI agent on Linux means it can write, run and connect to only what its task needs, on the machine it runs on, not only in the API tokens it holds. The practical way to get there is from evidence: record the agent doing the task once, turn that run into a contract, then remove every entry later runs never use. Tego does each step: tego watch records, tego learn proposes a contract, and tego drift and the dashboard's Tighten and Unused tabs show what to remove.
For the bigger picture, read AI agent security on Linux. We make Tego; claims about it link its docs.
Why scope the host, not only the credentials?
A scoped token limits what the agent can do in one service. It does not stop the agent reading ~/.ssh, running curl to a host you never meant, or deleting a folder next to the project, because the agent runs as you. A host contract covers those: the folders it may write, the programs it may run and the hosts it may reach, enforced by the Linux kernel and Tego's supervisor outside the agent. Do both.
Step 1: Record a run
tego watch -- <your agent command>tego watch with no contract refuses no file, program or host: the agent has your full access while it is recorded. Record a task and a project you trust (Write a Tego contract).
Step 2: Turn the run into a contract
mkdir -p ~/tego-contracts
tego learn <run> --out ~/tego-contracts/agent.yaml
tego compile ~/tego-contracts/agent.yamltego learn drafts a contract from a finished run: "what that run did and no more." Read it before you use it. It allows what the run did, mistakes included, with a few exceptions it names in comments: writes outside the project, risky sockets such as the SSH agent or the container daemon, and any address the run's secrets may have gone to. It never removes the built-in deny_read entries that keep ~/.ssh and other secrets out of reach. Write the file outside the project, as above, and outside every fs.write entry the proposal lists, because Tego refuses a contract the agent could rewrite. tego compile prints the rule table it makes.
Step 3: Run under it, then tighten
Run the agent under the contract a few times, on the real tasks (tego run ~/tego-contracts/agent.yaml from the project folder runs the contract's own command). Then, for each run:
tego drift <run>compares what was allowed with what was used (README).- The dashboard's Unused tab (Unused permissions in DASHBOARD.md) lists the entries the contract granted and the run never used.
- The Tighten tab (called Least privilege in DASHBOARD.md) shows, for a run under a contract, the smallest change to the contract the run suggests, as a contract to download. It keeps your deny and ask entries. On a run where secrets were read next to a send that got through, it leaves out the addresses where the secrets went, and a red notice says so. A destination recorded only by host name cannot be matched, and then the notice says the proposal may still allow it (DASHBOARD.md).
Remove what no run uses, compile again, and repeat. The dashboard docs show each tab.
What does a run not tell you?
- What a run did is not what is safe. A proposal allows what happened, mistakes included. A host the agent reached once is not a host it needs.
- Reads. A proposal never restricts reads, whatever was recorded. A contract limits reads only through
fs.deny_readand, at Basic,fs.ask_read, which holds a read until you answer, so reads stay open except for the built-in list and what you add. Separately, at Basic under the defaultrecord: summary, reads are not recorded, so a run's Unused list andtego driftcannot say whether adeny_readentry was exercised (protection levels). - Rare paths. A task that needs a program or host once a month will be refused the first time it does, after you tighten. That refusal is in the record, and the fix is a new entry in the contract.
- Inside an allowed program.
exec.allow: [python3]decides which programs start, not what Python does once it runs.
Keep the contract in version control, in a folder the agent cannot write, and review a change to it like a code change.
Next steps
- Keep AI agents away from your SSH keys and .env files and Stop an AI agent deleting files outside the project cover reads and writes in detail.
- A tamper-evident audit log for AI agents explains the record the steps above read.
- Write a Tego contract lists every key.
Sources (4 links)
Read on 6 November 2026.
- Tego: README, DASHBOARD.md, TIERS.md, Write a Tego contract.
Read next
Your agent doesn't need your SSH keys
Keep your agent out of your SSH keys, with a file to copy.
Stop your agent deleting your files
Let your agent change only the folders you name.
A record of what your agent did
A record of each run that shows any later edit.