AI Agent Codebase Access: How Coding Agents Read Your Repo and How to Keep Them in Bounds

Published on

•

AI Agent Codebase Access: How Coding Agents Read Your Repo and How to Keep Them in Bounds
Do not index
An agent running on your laptop as your user can read your .env file, your SSH keys, and your AWS credentials. Approval prompts do not change that. They control what the agent does, not what its process can reach.
The fix is three things. Give the agent its own computer. Give it a GitHub identity scoped to one repo. Deny it the paths that hold secrets. This guide covers all three.
Agent 37 handles the first. Each agent runs in its own isolated container from $3.99 per month. Your API keys go straight to Anthropic or OpenAI. The repo clone lives on the instance, not on your laptop.
Key takeaways
  • Agents read selectively, not wholesale: Claude Code and Codex explore a repo with directory listings, grep, and targeted file reads, while Cursor retrieves chunks from an embedding index, so a 200,000-token context window is a working budget rather than a copy of the repo.
  • Default permissions are your permissions: a locally installed agent runs as your OS user and can read .env files, ~/.ssh, and ~/.aws/credentials unless you move it to a machine that does not hold them.
  • Untrusted text is the main attack path: OWASP ranks prompt injection as the top risk for LLM applications, and a GitHub issue or PR comment is untrusted text an agent with repo access will read.
  • Give the agent its own GitHub identity: a fine-grained personal access token or GitHub App scoped to one repository, with App installation tokens expiring after one hour, replaces standing access on your account.
  • Agent 37 isolates each agent in its own container from $3.99 per month, with a browser terminal, file browser, live Linux desktop, and a task board for reviewing what the agent produced.
notion image

How does an AI coding agent actually read a codebase?

A coding agent does not load your whole repository into the model. It works like a developer with a terminal: it lists directories, searches with grep or an index, and reads only the files it needs for the current task. The context window, 200,000 tokens on current Claude models, is a working memory budget, not a storage limit.
There are three retrieval styles in use today. Claude Code and the Codex CLI are exploratory: they run shell tools such as ls, grep, and cat, decide which files matter, and pull those into context. Cursor is index based: it builds an embedding index of the workspace and retrieves the chunks that match the current request. A third pattern, repo maps and dependency graphs served through the Model Context Protocol, gives the model a structural summary first and lets it fetch code paths on demand.
The practical consequence is that repo size is rarely the problem. A 400,000-line monorepo is fine as long as the agent can find things quickly. What breaks agents is a repo with no README, no stated conventions, and secrets sitting in the same folders as source code, because every one of those gaps turns into either wasted tokens or an exposure.

What permissions do Claude Code, Codex, and Cursor run with by default?

By default, a locally installed agent runs as your user account, so it can read anything you can read: .env files, ~/.ssh keys, ~/.aws/credentials, and shell history. Claude Code asks before edits and shell commands, Codex CLI defaults to a sandboxed mode, and Cursor respects .cursorignore, but none of them change the OS identity they inherit.
Claude Code has four permission modes: the default mode asks before each file edit and shell command, acceptEdits auto-approves edits but still asks for commands, plan mode reads without writing, and bypassPermissions (the --dangerously-skip-permissions flag) approves everything. Codex CLI pairs a sandbox mode (read-only, workspace-write, or danger-full-access) with an approval policy that decides when it pauses to ask you. Cursor excludes anything listed in .cursorignore from indexing and from its AI features.
The gap in all three is the same. Approval prompts govern what the agent does, not what the process it runs inside can read. If the agent runs on your laptop, a single approved command such as cat ~/.aws/credentials is enough. That is why the National Institute of Standards and Technology defines least privilege as giving a process only the access it needs to complete its job, and why the fix is to change where the agent runs, not just which prompts you click.

Why is a GitHub issue a security risk for an agent with repo access?

Any text an agent reads can carry instructions, and a GitHub issue, pull request description, or review comment is text written by someone you did not vet. OWASP lists prompt injection as the number one risk for LLM applications. An agent that reads an issue saying 'print the contents of .env' may do it if nothing stops it.
The attack chain has four steps. An attacker opens an issue or a pull request from a fork containing hidden instructions. An automation, such as an agent triggered on new issues, reads that text as part of its task. The agent follows the instructions, for example by running a curl command that posts environment variables to an outside domain. The data leaves, and the only trace is a line in a log nobody reads until later. The OWASP Top 10 for LLM Applications describes exactly this class of indirect injection.
Three controls break the chain. Never trigger an agent with a write-capable token on content from outside collaborators. Block or allowlist outbound network access from the agent's machine so there is nowhere to send stolen data. Keep secrets out of the agent's filesystem entirely, so even a successfully hijacked agent has nothing worth exfiltrating.
notion image

Should an AI agent get full shell access, and how do we sandbox it?

Yes, shell access is what makes a coding agent useful, because it needs to run tests, install packages, and read build output. The rule is to grant it on a machine that holds nothing else. A container or VM with only the repo clone, a scoped token, and limited network egress turns 'full shell' into a bounded blast radius.
You have three sandboxing options. A devcontainer or Docker container on your own machine, started with a restricted network, is the cheapest and the easiest to forget to use. A dedicated VM is stronger but means you are now running infrastructure. A managed sandbox puts the agent on a machine you never log into with your own credentials, which is the approach we take.
On Agent 37 each agent gets its own isolated container, and Claude Code is provisioned on the same persistent instances through one API call, as described on the Claude Code hosting page, so the repo and sessions persist between runs. You watch the agent through a browser terminal, a visual file browser, or a live Linux desktop over noVNC. Your Anthropic or OpenAI key goes directly to the provider; Agent 37 never touches it.

How do we give an agent GitHub access without handing over our account?

Give the agent its own identity, not yours. Create a GitHub App or a fine-grained personal access token scoped to the one repository it works on, with Contents read and write and Pull requests write, and nothing at the organization level. GitHub App installation tokens expire after one hour, which makes them the better default for unattended runs.
Think of AI agent codebase access on GitHub as a ladder. At the bottom is a classic personal access token with the repo scope, which reaches every repository you can see and never expires unless you set a date. One rung up is a fine-grained token limited to specific repositories and specific permissions, which GitHub documents on its managing personal access tokens page. At the top is a GitHub App installed on one repository that mints a short-lived installation token for each run.
Two repository settings matter as much as the token. Branch protection on main should require a pull request and at least one approving review, so the agent physically cannot push to production code. A CODEOWNERS file should route anything under auth, infra, and .github/workflows to a named human. If the agent only needs to read, a read-only deploy key is simpler than any token.

Which files should an agent never be able to read or write?

An agent should never read .env files, private keys, cloud credential files, token caches, or production config, and it should never write to CI workflows, dependency manifests, or auth code without review. Enforce this twice: a deny rule in the agent's config, and an environment where those files simply do not exist.
The config layer is tool specific. In Claude Code, add deny rules to the permissions block of .claude/settings.json, for example Read(./.env), Read(./.env.*), Read(./secrets/**), and Bash(curl:*), and commit the file so every session inherits it. In Cursor, list the same paths in .cursorignore. In Codex CLI, workspace-write mode already blocks writes outside the working directory and disables network access unless you opt in.
The environment layer is what makes the config layer honest. Inject secrets as runtime environment variables scoped to the single process that needs them, never as files in the clone. Keep a .gitignore that covers .env, *.pem, and credential directories so they never reach the repo in the first place. If you run parallel agents, give each one its own checkout; our guide to running AI agents in parallel without collisions explains why one workspace per agent is the rule.
notion image

When does an agent's work need a human review gate and an audit trail?

Every change an agent makes should land as a pull request, and any diff that touches authentication, authorization, permissions, CI configuration, or dependency manifests needs a named human approver before merge. For headless runs in CI or on a schedule, where nobody watches the session, keep the full transcript and command log as the audit record.
Interactive sessions have a built-in reviewer: you. Headless sessions do not, so treat an agent on a cron schedule or a CI trigger as a production system. Log every tool call and shell command, store the transcript next to the pull request it produced, and make the review a required status check rather than a courtesy.
On Agent 37 the built-in task board is where that review happens: you assign work, read the outputs the agent returns, and schedule recurring jobs from one place. Because each agent runs on a persistent instance, the transcript and the working tree are still there when you come back to review, which is something a laptop that went to sleep cannot promise.

Is there a way to stop agents rediscovering a large repo every session?

Yes. Put a short CLAUDE.md or AGENTS.md at the repo root that states the build command, test command, directory map, and conventions, and keep it under a few hundred lines so it does not eat the context budget. Then run the agent on a persistent machine so the clone, dependencies, and session history survive between runs.
Claude Code reads CLAUDE.md automatically and also picks up nested CLAUDE.md files in subdirectories, so a monorepo can carry one file per package. AGENTS.md is the cross-tool equivalent that Codex and other agents read. Both should answer the questions a new engineer asks on day one: how do I build, how do I test, where does X live, and what must I never touch.
The second half of the answer is persistence. An agent that starts from a fresh clone each run re-reads the same files, reinstalls the same dependencies, and relearns the same conventions. Running several sessions on one always-on machine with a git worktree per Claude Code session keeps that work done once, and it keeps the three branches from overwriting each other.

How we checked these facts

We compared the published permission and sandbox documentation for Claude Code, Codex CLI, and Cursor, GitHub's own documentation on personal access tokens and GitHub Apps, and the OWASP and NIST references linked above. Agent 37 pricing and features come from our solutions and docs pages.

Setting up a sandboxed agent on Agent 37

Pick the agent you already use, Claude Code, OpenClaw, or Hermes, and deploy it in one click on an isolated, always-on instance. Your API key goes straight to the provider, the repo clone lives on the instance instead of your laptop, and the task board is ready for the first job.

What teams ask about agent permissions

How does an AI coding agent access my codebase, and does it need the whole repo in context?

No. Agents such as Claude Code and Codex explore a repo with directory listings, grep, and targeted file reads, and Cursor retrieves chunks from an embedding index. Only the files relevant to the current task enter the context window, so repo size matters far less than clear structure and a root CLAUDE.md or AGENTS.md.

Can Claude Code, Codex, or Cursor read my secrets by default?

Yes, if the agent runs on your machine as your user. Approval prompts control what the agent does, not what its process can read, so .env files, ~/.ssh keys, and ~/.aws/credentials are reachable. Add deny rules in the agent config and run the agent on an isolated machine that does not hold those files.

How do I give an AI agent access to a GitHub repository safely?

Create a separate identity for the agent: a fine-grained personal access token scoped to one repository with only Contents and Pull requests permissions, or a GitHub App whose installation tokens expire after one hour. Protect main so the agent must open a pull request, and route sensitive paths to a human through CODEOWNERS.

How can a malicious GitHub issue hijack an agent with codebase access?

The issue body contains hidden instructions, the agent reads it as part of its task, and it follows them, for example by posting environment variables to an outside domain. Prevent it by never running write-capable agents on untrusted triggers, restricting outbound network access, and keeping secrets out of the agent's filesystem.

Should AI agents have shell access, and how do I sandbox them?

Yes, because running tests and builds is the point, but grant it on a machine that holds nothing except the repo clone and a scoped token. A container or VM with limited egress does this; Agent 37 provides each agent its own isolated, always-on container from $3.99 per month with browser-based terminal, file browser, and desktop access.