# Keep the real key off the laptop

*Part 2 of 4 in Keep the key out of the agent.* [*Part 1*](https://devops-stories.hashnode.dev/the-8-000-key) *ended on a leaked AI key that cost about $8,000, a leak we still can't trace, and one thing we did know: nothing capped what the key could spend.*

My first plan had eleven parts. The idea behind it fits in one line: real keys never sit on a laptop.

After the bill, I sat down to write what we'd change. The plan starts from where our keys were. They sat in `.env` files in project folders, on laptops, next to coding agents that could read the whole project. Whoever held one of those keys could spend without limit, and no key had a named owner.

So the question for this part is simple to ask and harder to answer: what would we build if we started from the rule "laptops only report, servers block"?


Watch the video: https://youtu.be/ilpdNhkJhBM

## The idea, before any tool

Here is the whole plan in three sentences, as I wrote it:

> Real keys stay in AWS and never sit on a laptop. Laptops only monitor and report. The servers do the blocking.

Each sentence carries a decision.

The first moves the thing worth stealing. If the real provider key lives only on a server, a stolen laptop file holds something smaller.

The second says what a laptop is trusted to do. A laptop can look around and tell us what it sees. It isn't trusted to enforce anything, because the person at the keyboard can switch off anything that runs there, by accident or in a hurry.

The third puts the blocking where nobody can switch it off from a laptop.

Everything below is one of those three sentences turned into a part you can run.

![The laptop holds the real key and calls the provider directly. Look at the red ENV card: that's what the plan moves.](https://cdn.hashnode.com/uploads/covers/6807ccab4d84c3728e906261/ece68348-3a4e-4af1-932a-0bbcd24aef2b.png align="center")

*Today: the real key sits in a* `.env` *file, and the agent calls the provider with it.*

## The gateway holds the real keys

The centre of the plan is an AI gateway: one service that sits between engineers and the AI providers, holds the real keys, and hands out keys of its own. The plan uses LiteLLM, an open-source gateway, running on AWS.

Each engineer gets a personal key per project. In the plan, that key expires within 2, 4 or 8 hours and has a cost cap. Those numbers are the plan's choices, not something we've measured yet.

This one part fixes three things from Part 1:

- A stolen key with no limit. A gateway key runs out of money and out of time.
- Shared keys. Each key belongs to one person and one project.
- No owner per key. When a key misbehaves, we know whose it is.

![The gateway in AWS holds the real keys; the agent gets a personal, short-lived, capped key.](https://cdn.hashnode.com/uploads/covers/6807ccab4d84c3728e906261/09df6946-8993-4ae5-81e1-005822a23367.png align="center")

*The gateway holds the keys. Look at the agent's card: its key is now personal, short-lived and capped.*

## Closing the way around

A gateway only helps if people use it. An engineer with a deadline and their own provider key can call the provider directly, and the gateway never sees it.

So the plan puts a zero-trust network layer in front. Zero trust means no request is trusted because of where it comes from; each one has to prove who it is. The plan uses Cloudflare Zero Trust for this. It gives engineers secure access to the gateway from the office or from home, and it blocks direct calls to the AI providers.

![Zero trust lets the laptop reach the gateway and blocks the direct line to the providers.](https://cdn.hashnode.com/uploads/covers/6807ccab4d84c3728e906261/f65bf7d2-e8ea-4eda-9886-56e44d880f7e.png align="center")

*No way around it: the direct line to the provider turns red.*

## The laptop side: watch and report

Four parts run on or near the laptop. None of them blocks anything on its own.

The first is a small CLI. It signs engineers in with short-lived AWS credentials from AWS SSO (single sign-on, where you log in once and get credentials that expire). It passes secrets in when a program runs, so there's no `.env` file with real keys sitting in the project. And it scans a project before a coding agent starts. It fixes `.env` files with real keys, agents reading secrets they shouldn't, and long-lived AWS keys.

The second is a laptop checker. It lists the AI tools on the laptop, checks agent settings, finds secret files, and plants fake "canary" keys. A canary key is a decoy: it works for nothing, so if anyone ever uses it, we know a file was read that shouldn't have been. The checker sends metadata only and never reads prompts. It fixes the fact that we couldn't see which laptops were in a risky state, and it catches leaks we'd otherwise miss.

Then the desktop AI app checks, the same idea for desktop apps: Claude Desktop, Codex, Cursor and Antigravity, checked for unsafe or unapproved settings.

Last, a browser extension. It warns, or blocks, when someone pastes secrets or project files into ChatGPT, Claude, Gemini and similar sites.

![The CLI, the laptop checker and the browser extension are ringed: they watch and report.](https://cdn.hashnode.com/uploads/covers/6807ccab4d84c3728e906261/2c748af7-8336-48a9-ace7-f64fabff845d.png align="center")

*Laptops only report. The new cards watch; none of them is the last line.*

## The server side: block and respond

The rest runs on servers, where an engineer can't turn it off from their own machine.

- A control plane in a separate AWS account. It collects the laptop reports and shows each team lead their team's status. It can't read secrets. A separate account keeps the place that sees every laptop's state apart from the place that holds the keys.
- Automated response. A leaked key gets disabled or rotated automatically. For a key that someone outside the team also holds, we rotate after they confirm, so we don't break their systems.
- Device management. Safe settings get pushed to every laptop, instead of depending on each engineer to apply them.
- GitHub guardrails. A secret scan before each commit and again in CI, a global `.gitignore` that covers `.env`, and an organisation lockdown on repository visibility, forks and tokens. Part 1 had a key that stayed in a private repository's Git history after it was removed. This is the part aimed at that.

![All eleven parts in place: reports flow to a control plane that can't read secrets.](https://cdn.hashnode.com/uploads/covers/6807ccab4d84c3728e906261/2e645a38-a4bc-4f68-ab00-4f8bdcb06604.png align="center")

*The servers do the blocking. Follow the dashed line: the laptop sends metadata only.*

## What it costs

I don't have a price for this plan, and I won't make one up. It's still a proposal. Nothing in it has been built.

What I can say is the trade. Eleven parts means eleven things the team has to run, update and answer for. A gateway is a service with uptime. A laptop checker is software on every machine. A browser extension needs to keep up with every AI chat site. The plan swaps one risk, a key with no limit on a laptop, for a lot of moving parts. I proposed it anyway, because Part 1 showed what the other side costs. If you copy it, count the parts before you start.

## What we turned down, or left for later

| Option | Why not now | When we'd switch |
| --- | --- | --- |
| Full traffic inspection | It reads people's traffic, so it needs approval first | Only if it's approved, and if secrets keep leaking through personal AI chat accounts that the extension misses |
| Laptops that do the blocking | Anything on a laptop can be switched off at that laptop | If the device management can lock a setting so the engineer can't change it |
| One shared key per team | No owner, no per-person limit, and one leak exposes everyone | Never, for real provider keys |

## The gap the plan left

When I read the plan again, one thing bothered me. The gateway, the network layer and the GitHub guardrails all protect the key on its way somewhere. None of them changes what the coding agent can do while it runs. The agent still ran with whatever the laptop could reach: every file in the project, and every host it could connect to.

That's the part a sandbox for the agent addresses. Then AWS's open-source Strands Box came out, and it went straight at that gap.

## Three questions to test yourself

1. Your gateway hands out keys that expire in two hours. An engineer says their agent keeps failing in the middle of long runs. What do you change first, and what do you refuse to change?
2. The laptop checker reports that a canary key was used from an IP address you don't recognise. What do you know, and what don't you know yet?
3. A team lead asks to turn off the zero-trust layer for one week because a demo needs a direct provider call. What do you say?

<details>
<summary>Answers</summary>
<ol>
<li>First ask whether the run really needs a longer key, or whether the tool can fetch a fresh one from the gateway. If it must, that project moves from 2 hours to 4 or 8. What you refuse is removing the expiry or the cost cap, because those are the two things Part 1's key didn't have.</li>
<li>You know a file holding the canary was read and the key was used outside your systems. You don't know how it was read: the agent, a malicious package, a backup, a copied folder. Treat every real secret near that canary as exposed, rotate them, and then look for the path.</li>
<li>Give the demo its own gateway key with a small cap and a short expiry, and keep the direct path blocked. A week-long exception for one team is a week-long exception for anyone who learns about it.</li>
</ol>
</details>

To audit your own laptop against this plan, there's a one-page table in the series repo: [github.com/shadreza/keep-the-key-out-of-the-agent](https://github.com/shadreza/keep-the-key-out-of-the-agent/tree/main/part-2-keep-the-real-key-off-the-laptop).

Next, in [Part 3](https://devops-stories.hashnode.dev/what-aws-s-strands-box-changes-for-coding-agents): what AWS's Strands Box changes, which part of this plan it replaces, and which parts it leaves.
