Stop Handing Your AI Agents (and Your Deploy Scripts) the Keys to Everything Skip to content
Stop Handing Your AI Agents (and Your Deploy Scripts) the Keys to Everything

Stop Handing Your AI Agents (and Your Deploy Scripts) the Keys to Everything

By Amitav Roy Published September 25, 2026 8 Min Read

Personal access tokens give deploy scripts and AI agents unlimited blast radius. The fix is short-lived GitHub App tokens minted per deploy and revoked seconds later.

If you've ever automated a deployment, you've probably hit this moment: your script needs to pull code from a private GitHub repo, and it needs some kind of credential to do it. Nine times out of ten, engineers reach for the easiest option — a personal access token that's already sitting around, one that can read (and often write) to every repository they own.

It works. It's also a much bigger risk than most teams realize, and in 2026, with AI agents running scripts, sandboxes, and CI pipelines on our behalf, it's a risk that's only getting bigger.

Here's the problem, why it matters, and a genuinely simple fix.

The Problem: Deploy Scripts Need Git Access, So We Hand Over Everything

Picture a typical deploy setup: a script logs into your server, pulls the latest code, installs dependencies, and restarts things. Somewhere in there, it needs to authenticate with GitHub to do the git pull.

Most teams solve this one of two ways:

  • Type in credentials manually, every single deploy. It works, but it defeats the point of automation — someone has to sit there and babysit it.
  • Reuse an existing personal access token. Faster, but that token was probably created months ago, for a completely different purpose, and it can likely touch every repo you own.

Neither option was really designed for this job. They're workarounds that happen to function.

The Risk: One Token, Unlimited Blast Radius

Here's the uncomfortable question worth asking your team: if that deploy token leaked tomorrow, what could someone do with it?

For most personal access tokens, the honest answer is: a lot more than "pull one repo." Depending on how it was created, it might read and write to every private repository you own. It might sit valid for months or years, because nobody remembers to rotate it. It lives on whatever machine runs your deploys — a laptop, a CI runner, a server — as a standing, permanent secret.

The mismatch is the real issue: the credential lives forever, but you only actually need it for the few seconds it takes to run git pull. Every extra day that token sits around valid is a day it can be lost, leaked, or misused for something you never intended.

The Better Way: Mint It Just Before You Need It, Then Throw It Away

The fix isn't a complicated security overhaul — it's a mindset shift: instead of keeping one powerful credential around forever, generate a brand-new, narrowly-scoped credential right before you need it, use it once, and kill it immediately after.

In practice, this means using a GitHub App instead of a personal token. Think of a GitHub App as a separate, purpose-built identity — not "you," but a dedicated helper you create once, and permanently restrict to exactly what it's allowed to do (e.g., "read code from this one repository, nothing else, no write access, no other repos"). No matter what happens later, that ceiling never moves.

Here's the flow, in plain terms:

  1. Your deploy script proves who it is using a private key that never leaves your machine.
  2. GitHub hands back a short-lived, single-purpose token — scoped to exactly one repo, read-only.
  3. That token is used for the git pull.
  4. Immediately after, your script tells GitHub to kill that token — it's dead within seconds, not hours.

Same job gets done. The difference is what's left lying around afterward: nothing.

Subscribe to my newsletter as I bring more such articles on application and infra security.

Are you concerned with security?

The Peace of Mind

This is the part that actually matters for you as a decision-maker, not just for the engineer writing the script:

  • Deploys stay fully automated — no one's typing in a password at 11pm.
  • Your broad, powerful personal token is never involved in deploys at all. It's simply out of the picture, which means it's out of the risk equation too.
  • Even in a worst-case scenario — a credential accidentally logged, pasted somewhere it shouldn't be, or exposed by a bug — what leaked is a read-only key to one repository that's already expired by the time anyone could act on it. Compare that to a leaked personal token that can touch your entire GitHub account for months.
  • It scales without adding risk. Got five projects deployed the same way? They all share the same setup — you're not creating five more standing secrets, you're reusing one tightly-controlled identity across all of them.

That's the real win: not "more secure" in some abstract sense, but measurably smaller consequences if something ever does go wrong.

Why This Matters Even More in the Age of AI Agents

Here's the part that's easy to miss if you're thinking about this as a one-off deploy-script problem: it isn't anymore.

We're now living in a world where AI coding agents run code in sandboxes, connect to your repositories, and execute scripts largely unsupervised. That's incredibly useful — and it also means credentials are being handed to more systems, more often, with less direct human oversight than ever before. You've likely seen the headlines this year about sandboxed AI environments at major AI companies and platforms being tricked or misconfigured in ways that exposed embedded secrets and access tokens. The pattern is consistent: wherever a long-lived, broad credential sits quietly in an environment an agent can touch, it becomes a target.

This is exactly why the short-lived, narrowly-scoped approach matters more now than it did five years ago. If an AI agent's sandbox only ever has access to a token that's read-only, scoped to one repo, and already expired by the time anyone could misuse it — a leak stops being a headline and starts being a non-event. You're not trying to guess which future AI tool, script, or automation might mishandle a secret; you're making sure that whatever does leak simply isn't worth much.

How to Set Things Up

The good news: this is a one-time setup, and it's genuinely not complicated.

  1. Create a GitHub App in your GitHub developer settings — give it a name, and skip anything you don't need (webhooks, extra permissions).
  2. Set its permissions to the bare minimum — for a deploy use case, that's just "read code," nothing else.
  3. Install it on the specific repository (or repositories) it should have access to. You can always add more later.
  4. Generate its private key and store it safely on the machine that runs your deploys — never on the server itself, never in your codebase.
  5. Add a small, reusable script that uses that key to request a fresh token right before each deploy, and revokes it right after. This is the only new piece of "code" in the whole setup, and it's the same few lines regardless of which project you're deploying.
  6. Wire it into your existing deploy process — whatever that already looks like (Ansible, a shell script, a CI job) — swapping out wherever it used to ask for a username/password with a call to that script instead.

From there, every future project follows the same two steps: add the repo to your existing App, and point your existing script at it. No new credentials, no new setup, no new risk added per project.

FAQ

What's the difference between a personal access token and a GitHub App token? A personal access token is tied to your account and is often broadly scoped and long-lived. A GitHub App token is tied to a separate, purpose-built identity that you can restrict to specific repositories and specific permissions (like read-only), and the tokens it issues are short-lived by design.

Do I need to be a security expert to set this up? No. It's a one-time setup in GitHub's UI (create the App, set permissions, install it on a repo) plus a small reusable script. Most of it is configuration, not code.

How long does a short-lived token actually last? GitHub caps these tokens at one hour by default, but the real safeguard is that your script explicitly revokes the token the moment it's done using it — usually within seconds, not the full hour.

Can one GitHub App be used for multiple projects? Yes. You install the same App on as many repositories as you need, and each deploy simply requests a token scoped to the one repo it's working with. No need to create a separate App per project.

Why does this matter more now than it used to? Because credentials are no longer only handled by humans running scripts — AI agents, sandboxes, and automated pipelines increasingly handle them too, often with less direct oversight. Narrowly-scoped, short-lived credentials mean that if one of these systems ever mishandles a secret, the damage is small and temporary instead of broad and lasting.

What's the actual cost of switching to this approach? Mainly a bit of one-time setup — creating the App and writing a small script. There's no ongoing maintenance, no rotating secrets on a schedule, and no added friction to your existing deploy process once it's in place.

Software development

Continue Exploring

Need help with system design or architecture?

I work with engineering teams on technical audits, architecture reviews, and scaling strategy. Let's discuss your challenges.

Let's talk