The Zeroic Journal

AI coding agent access to GitHub repo: what to lock down first

Cursor, Lovable and Supabase's MCP server all want write access to your product. Five settings decide what they can break, and who answers for each commit.

On this page 7 sections
  1. Scope AI coding agent access to GitHub repo
  2. Protect main so agents can’t merge
  3. Keep production secrets away from agents
  4. Give database agents their own scoped token
  5. Know which commits came from which agent
  6. How to decide what each agent gets
  7. Performalise: commit and deploy signals for 5+ enterprises

Limit AI coding agent access to GitHub repo by repo: an app install or fine-grained token that names one repository, a protected main branch that needs one human approval, and secrets the agent never sees. GitHub App installation tokens expire after 1 hour. Aim for that lifetime with every credential an agent holds.

This matters now because the agents stopped waiting for you. Cursor’s cloud agents run in their own VM and open a pull request for every run by default. Lovable can keep working while it waits for answers to its questions. Supabase’s MCP server and Bubble’s MCP let outside agents touch your database and your app. Each one asks for access once, at setup, usually in a dialog a founder clicks through. The five settings below decide what that click hands over.

Scope AI coding agent access to GitHub repo

Most agents reach GitHub one of two ways: a GitHub App you install, or a personal access token someone pastes in. Both can be narrow. Both default to wide.

Classic tokens are the one to refuse. GitHub’s token documentation says a classic token can reach every repository its owner can, “including all repositories in your organizations and personal repositories”. If a contractor pastes their classic token into an agent, that agent can read your repo and every other client’s repo they work on. Fine-grained tokens are limited to one owner, can be restricted to named repositories, and grant permissions one by one. GitHub recommends them “whenever possible”, and for long-lived integrations it recommends a GitHub App instead.

App installs ask for more than you’d guess. Lovable’s GitHub integration docs list the permissions its app requests: Contents, Pull requests, Workflows and Administration, all with write access. That’s more than an agent needs to edit code. The install screen offers “All repositories” or “Only select repositories”. Pick select, every time, and add repos one at a time as projects start.

Short-lived beats long-lived. A GitHub App’s installation access token expires after one hour and can be narrowed further to specific repositories and permissions. Cursor’s release notes say its cloud agents refresh GitHub tokens during long runs, which is the pattern you want: a token that dies on its own if the agent or the vendor is compromised. A fine-grained token makes you pick an expiry at creation. Pick 30-90 days and skip “no expiration”.

The opposing view is that scoping slows the team down: one org-wide token is easier than ten per-repo ones. That’s true for about a week. After that, nobody remembers which agent holds which token, and a leak means rotating everything.

Protect main so agents can’t merge

An agent with write access can push to any branch you haven’t protected. Branch protection on main is the setting that turns “the agent changed production” into “the agent opened a pull request”. Turn on these:

  • Require a pull request with 1 approval. Two if the repo handles payments or health data.
  • Require approval of the most recent push by someone other than the pusher. This stops a person from approving the agent’s work and then letting the agent add one more commit.
  • Dismiss stale approvals when new commits arrive. An approval should cover only the code someone read.
  • Require status checks to pass. Tests and the build, at minimum.
  • Apply the rule to administrators. By default, branch protection doesn’t apply to repository admins. If the founder is an admin and the agent runs under the founder’s account, the rule protects nothing until you tick this box.

Force pushes and branch deletion are blocked by default once a rule exists, so leave those alone.

Protection doesn’t break the tools. Cursor’s cloud agents clone the repo, work on a separate branch and push changes back for review. When GitHub rejects a push to Lovable’s synced branch, “most often due to branch protection rules”, Lovable pushes to a lovable-sync branch instead and you merge it through your normal review. The agent keeps working. Main just stops moving without a person.

Keep production secrets away from agents

An agent that can read a secret can be talked into sending it somewhere. In June 2026, Microsoft’s security researchers showed a crafted GitHub issue steering the Claude Code GitHub Action into reading the workflow’s environment, which exposed its ANTHROPIC_API_KEY. Anthropic fixed it in Claude Code 2.1.128 on May 5, 2026, after Microsoft reported it on April 29. The fix closes that hole. The pattern stays: any agent that reads text an outsider wrote (issues, PR comments, a dependency’s README) and also holds secrets is one clever paragraph away from leaking them.

Microsoft’s recommendation is the “Agents Rule of Two”: a workflow shouldn’t combine all three of untrusted input, access to sensitive secrets, and the ability to change state or talk to the outside world. For a founder, that turns into three rules:

  1. Agents get test keys. Stripe test mode, a staging database, a sandbox API key. Production keys live in your hosting provider’s environment settings, which the agent doesn’t see.
  2. Secrets go in the tool’s secrets store. Cursor’s docs recommend its Secrets tab over saving .env.local files in environment snapshots, which can persist them. Since October 19, team admins can switch on “Disable personal secrets” so members can’t hand agents keys the team never approved.
  3. Turn on push protection for the repo. GitHub’s push protection for your user account is on by default but only covers public repositories. Push protection for the repository itself is off by default, and it’s the one that blocks a key before it lands in a commit.

The third rule matters more with agents in the loop. GitGuardian’s State of Secrets Sprawl 2026 counted 28,649,024 new secrets in public GitHub commits in 2025, and found Claude Code co-authored commits leak secrets at about twice the baseline. Of the valid secrets it found in 2022, 64% were still active four years later.

Give database agents their own scoped token

Your repo is half the product. The other half is the database, and MCP servers now let agents query and change it directly.

Supabase made scoped personal access tokens generally available on October 6, 2026. A scoped token can be limited to selected projects, with read or read-write set per capability (database, auth, storage and so on). SQL runs read-only unless the token has Database read-write, and revealing secret API keys needs its own permission. You set an expiry of up to one year, and you can’t widen a token later: you delete it and make a new one. The MCP server checks the token’s permissions on every tool call.

Two catches. Legacy account-level tokens still work until they expire or you delete them, and the browser flow for supabase login still creates an account-level token. If an agent or contractor set up the Supabase CLI that way, it holds the keys to every project on the account. Replace it with a scoped token passed through SUPABASE_ACCESS_TOKEN.

The second catch works in your favor. Since November 16, 2026, merging a branch through the Management API or MCP needs read-write on Production Branches, and development-only tokens get a permission error. Give agents a development-branch token, and production merges stay with a person, the same way protected main does in GitHub. Our Supabase CLI v3 guide covers the CI side of the same change.

Bubble works the same way at a different layer. Our Bubble MCP and Claude Code guide covers what its beta lets an outside agent edit and what it can’t touch.

Know which commits came from which agent

When three people and four agents commit to one repo, “who wrote this?” becomes a security question. Three settings answer it.

  • Co-author lines on agent commits. Cursor’s release notes say that since October 26, agent commits always include your Co-authored-by line, even with --no-verify. Keep that on. It’s how you, and tools like GitGuardian, tell agent commits from human ones.
  • Contractors work inside your organization. A contractor’s own fine-grained token, approved by you, runs under an identity you control. GitHub ties every token to the user who created it, and it stops working when that user loses access. Remove the contractor on their last day, and their agents lose access the same minute. Organization owners can require approval for fine-grained tokens and block classic ones outright.
  • One written rule for contractors’ agents. Which agents are allowed, on which repos, with which plan settings. If you’re hiring developers on a retainer, put it in the contract alongside the code ownership clause.

How to decide what each agent gets

Agent or toolAccess to grantWhat stays with a person
Cursor cloud agentsGitHub App on selected repos, team secrets only, restricted network egressMerging the pull request it opens
LovableApp install on “Only select repositories”, one repo per projectMerging lovable-sync into protected main
Supabase MCPScoped token, one project, development branches, expiry setProduction branch merges, secret API keys
Claude Code or other CI agentsRead and pull request permissions, no production secretsAnything triggered by an outsider’s issue or comment
A contractor’s agentsTheir seat in your org, fine-grained token you approvedOffboarding, done the day the work ends

If the agent can’t do its job with the left column, the job needs a person, not a wider token. Before you scope anything, run the Lovable security checklist: the keys and policies it covers are what a leaked agent token would reach.

Performalise: commit and deploy signals for 5+ enterprises

Performalise reads the work signals engineering teams already generate - commits, pull requests, deploys, sprint velocity - and turns them into coaching and delivery analytics. We built the ingestion layer that connects to project management tools, version control and CI/CD and normalizes it all into one event stream, then the AI models that spot delivery risk on top: commit frequency dropping, PRs stuck in review, sprint scope creeping mid-cycle.

Enterprise engineering data is some of the most guarded data a company has, so the access controls were built for enterprise buyers and the data handling is SOC 2 aligned. Performalise now runs across 5+ enterprises, and our engineers have been on the retainer since 2023.

The same discipline applies to your repo. The tool that reads your code gets the access its job needs, every credential has an owner, and a person decides what reaches production. Our senior developer retainer puts an engineer on your repo to set this up and to review what your agents ship. If an agent has already left the code in a state you don’t trust, code rescue by tool covers Cursor, Lovable and Bolt apps.

Frequently asked questions

Should I let an AI coding agent push directly to main?
No. Protect main so every change arrives as a pull request with one approval from someone other than the person who pushed it, and turn on the option that applies the rule to admins too. Cursor's cloud agents already work on their own branch and open a pull request, and Lovable falls back to a separate sync branch when GitHub rejects a push, so protection doesn't break either tool.
What GitHub permissions does an AI coding agent need?
Most agents need read and write access to repository contents and pull requests on the repositories they work in, and nothing else. Install the agent's GitHub App on selected repositories rather than all of them, and refuse classic personal access tokens, which reach every repository the person who made them can see. GitHub's own docs recommend fine-grained tokens or a GitHub App instead.
Can an AI agent leak my API keys?
Yes, if it can read them and also reads text an outsider wrote. In 2026 Microsoft researchers showed a crafted GitHub issue steering the Claude Code GitHub Action into reading workflow secrets, which Anthropic fixed in Claude Code 2.1.128. Keep production keys out of agent environments, give agents test keys, and switch on secret scanning push protection at the repository level.
How do I give an AI agent access to Supabase safely?
Create a scoped personal access token limited to the one project the agent works on, with read-write only on the capabilities it needs and an expiry date. Without Database read-write, SQL runs read-only. Since November 16, 2026, merging a branch through the Management API or MCP needs Production Branches read-write, so a development-only token keeps production merges with a person.
How do I control AI agents a contractor uses on my code?
Give the contractor a seat in your GitHub organization, require organization approval for fine-grained tokens and block classic ones. Agents then run under an identity you can revoke. Ask for agent commits to carry a co-author line so you can see which changes came from a tool, and remove the contractor's access on their last day, which also disables their tokens.

References

  1. GitHub Docs - Managing your personal access tokens
  2. GitHub Docs - Generating an installation access token for a GitHub App (1-hour expiry)
  3. GitHub Docs - About protected branches
  4. GitHub Docs - About push protection
  5. Lovable Docs - GitHub integration (permissions and sync branches)
  6. Lovable - Changelog (November 2026)
  7. Cursor Docs - Cloud Agents
  8. Cursor - Cloud Agents release notes
  9. Supabase - Scoped personal access tokens are now generally available
  10. Supabase - Merging a branch now requires Production Branches read-write
  11. Microsoft Security Blog - Securing CI/CD in an agentic world: the Claude Code GitHub Action case
  12. GitGuardian - State of Secrets Sprawl 2026

More from the journal

Hear from Khushi within 24 hours.

Khushi Arora Partner @ Zeroic

Want a senior engineer reviewing what your agents ship? Our retainer puts a senior engineer on your repo to set up branch rules, scoped tokens and secrets, then review agent pull requests before they reach main.

See retainer options, or book a 30-minute call