r/cursor • u/Gallegos_Daniel • 6d ago
Question / Discussion Teams using Claude Code / Cursor / Codex: who decides what the agents are allowed to do in your repos?
Genuine question about how teams handle this in practice..
Is there any written policy on what coding agents can touch (files, commands, packages, MCP servers), or is it "everyone sets their own"?
How do you deal with secrets and .env files when an agent works in the repo?
Has an agent ever done something it shouldn't have (deleted something, used a credential, installed a dependency)? What happened and how did you notice?
Does anyone outside engineering (security, compliance, a client) ask about this?
Do you use any tool for this, or is it just trust plus code review?
Short real stories are more useful than general opinions.
5
u/pluggedinn 5d ago
Simple. Do not have have prod env files on your machine. If it’s on your machine your agent is gonna find it. For the rest you give you agent everything it needs
4
u/Ok-Form1598 6d ago
on .env, hiding the file doesn't buy much. cursor's own docs say .cursorignore can't block the agent's terminal or mcp tools, and claude code's Read deny rules don't cover
grep -ror a script that opens the file itself, which is every test run that loads dotenv. what holds up is the local .env only ever has dev keys with tiny limits, and the real ones stay in the secrets manager where only CI pulls them. also check the permissions file into the repo so every agent gets the same denies. claude code saves each "don't ask again" to settings.local.json, so otherwise everyone's rules quietly drift.2
u/Substantial_Gap_6676 5d ago
What I'd write down first, short and inside the repo: the agent instructions file lists folders and commands that are off limits and the actions that need a human to say yes, like adding a dependency, running migrations, or touching CI. Keep prod secrets off dev machines entirely, because file deny rules don't stop a shell command or a test run from reading them. Run each agent task on its own branch and don't merge until someone has read the diff file by file. Once it's written down, it's also the thing you can show security or a client.
2
u/ranthishq 5d ago
real one: a background agent committed in the same checkout and swept in files i had staged by hand, caught it in git log. now a hook blocks git add -A and commit -a, every commit names its files
1
u/Lopsided-Ad-6298 5d ago
In my own setup the written policy is short and lives in the repo: a checked-in permissions file plus hooks that block the things I don't want an agent doing, like touching .env, force-pushing, or running anything that looks like a prod deploy. A markdown rule is only a suggestion, so the hook is the actual policy. For secrets I agree with the others, keep only low-limit dev keys on the machine and pull real ones in CI from a secrets manager. If a client or a compliance person asks, that one-page list of what agents can and cannot do is a lot easier to show than "we just review the diffs."
1
u/Theodosisgr 5d ago edited 5d ago
For the secrets and .env part of your question, check Kryptic's (https://kryptic.dev) daemon first approach, which keeps plaintext .env files out of the repos your agents work in.
A local daemon injects secrets over an OS socket when you press run, so you can skip both the .env file and the wrapper CLI.
The repo only keeps a commit-safe project ID in kryptic.json and it supports both pipelines and k8s.
1
u/serachellee 5d ago
Besides permissions, I also had to decide what the agent is allowed to invent in the UI. Early on an agent added a new gray and a button that was 2px taller than the rest, and nobody caught it until there were three slightly different grays and dark mode looked off. Now I keep a short list of components and color/spacing tokens in the repo, next to the permissions file. A new one-off color or a different button height gets flagged in review the same way a surprise dependency would. It took about an afternoon to set up, and the drift mostly stopped.
1
u/newtablecloth 5d ago
nobody's mentioned MCP servers yet, and in what I've seen they're the bigger gap. a repo deny list doesn't matter much if the agent has an MCP server holding a token that can write to prod Jira, Slack or the database. treat each server like a dependency: someone approves it, it's pinned to a version, and its token is scoped read-only unless there's a real reason not to be.
for package installs, the cheap check is in CI, not in the agent. if the lockfile changes, the PR needs an explicit human approval, so a surprise dependency can't slip through inside a big diff.
on how you'd notice: running the agent in a devcontainer with no cloud creds and limited network turns a lot of "it did something bad" into "it tried and failed", and the failure shows up in the logs.
+1 to Lopsided-Ad-6298 that the hook is the real policy and the markdown is just a hint.
1
u/samc621 5d ago
what i've seen hold up on small teams: the policy that sticks lives in the repo, not in a doc. commit the agent config (cursor rules, .claude/settings.json deny list, hooks) so every dev starts from the same floor, and review changes to it like code.
on .env, the comment above is right that ignore files don't stop the terminal. what helped more was keeping prod creds off laptops entirely and giving agents a dev-only token with no write access to anything shared.
on "how did you notice": almost always after the fact, from a weird diff or a broken env. that's the actual gap, nobody has a record of what the agent ran or why.
i work on agenttrail. guard is a free hook pack for the shared blocklist (https://github.com/agenttrailhq/guard), and the hosted side keeps searchable team history of agent sessions plus approvals for risky steps: https://www.agenttrail.sh/
1
u/thestoictrader 4d ago
Mostly "everyone sets their own," and that's the gap. What's worked for us in practice: keep .env out of the agent's reach (deny rules in the agent config, secrets in a manager, not the repo), require approval for shell commands and installs, and treat agent PRs like any other PR. Most surprises are a stray dependency or a distant caller getting broken, and review catches them.
1
u/ksajadi 3d ago
we have a very strict policy around it, but it needs some prep:
we use this method to make sure no bot can do anything harmful that can end up in production without human oversight.
we then have a bunch of workflows in bench47 that use review agents assess the PRs and raise alerts if needed. we also use it for secret protection (no secret reaches the agent but they can still use them to access apis and / or mcps).
obviously we arrived at this setup after having made a lot of mistakes: agents working on the same branch and deleting each other's work, until we strictly work in worktrees. secrets being exposed in the chat because the agent just printed a file they were not supposed to and we ended up rotating a lot of secrets and a lot of clean up.
on the secrets side (since you ask specifically): we store secrets in SOPs, and encrypt it with AWS KMS. this means decrypting secrets on a machine needs aws login, but also we explicitly block and SOPS cli action at the harness level (in our case .claude/settings.json). on machines that run agents autonomously, we use bench47 secret proxy with AWS KMS with a keyring that holds only certain service APIs and MCP creds.
for production investigation, we use postgres anonymizer with a "default block" so no PII or other sensitive information is exposed to the agents but they can still read the table structure and metadata for investigation.
agnets connect to production db over tailscale with readonly credentials that only has access to the anonymized tables.
there is a lot more i'm sure, but that's what i can remember so far!
1
u/No-Drawing9451 3d ago
Two rules fixed most of the collisions for me. One worktree per agent, never two agents in the same checkout. And an explicit allow list for safe commands (tests, lint, git status/diff), so anything outside it needs a yes from me. After that, merging is the only place agents meet, and you review it there.
1
u/tofutim8 3d ago
One of the answers to your "has an agent ever done something it shouldn't have" question that keeps showing up in my experience is not a stray dependency or a leaked credential — it's a distant caller breaking, and that's the one no permission list catches.
The sequence is always the same. The agent makes a small change to a shared function's signature or removes an early return. The diff is clean, the file it edited is in scope, the tests pass. What breaks is in a file nobody in the review looked at, because the reviewer was reading the diff and the diff didn't mention it.
That's a review-scope problem, not a permissions problem. Deny lists control what the agent may touch; they can't control what the agent's change breaks elsewhere. And "the reviewer reads the diff" is exactly the blind spot thestoictrader described above — most surprises are a distant caller getting broken.
The fix that generalizes: the question isn't "is this diff correct?" but "who depends on this?" If you can answer that before merging, the blast radius is visible and the permission question stops being the hard one.
Two things I'd add to the checklist that aren't in most of the answers above:
1. Impact analysis belongs in the same check, not in a separate tool. A tool that answers "what calls this function" is only useful if the agent actually runs it before making the change, and treats an unreviewed caller as a blocker. Otherwise it's a tool sitting in the toolbox that nobody calls at the moment it matters.
2. Cross-repo is where this gets real. "Distant caller" usually means another service, another repo, or a shared library. A single-repo view can't see it at all — the call site is in a checkout the agent isn't looking at. So the blast-radius question needs a multi-repo workspace to even be answerable, which is why most code search tools don't answer it well.
3. The permission file and the impact check are the same artifact. What surprised me building this: the highest-value thing you can check in CI isn't "did the agent touch a forbidden path" — it's "does this PR change a symbol that has callers outside the repo". Both are the same check run at two different times: once before the agent edits, once before the human merges.
We do this in srclight (43 tools, 19 languages, SQLite FTS5 + tree-sitter + embeddings, fully local; call graph + git blame/hotspots + multi-repo workspaces, MIT,
pip install srclight). Happy to go deeper on how we decide which edges are "confirmed" vs "inferred" if that's the interesting part — that distinction turned out to matter more than I expected, because an inferred edge presented like a confirmed one is how a graph starts lying.1
u/soulinas 4d ago edited 3d ago
I use Forge and there's a way for agents to ask for secrets such that you can safely let them store the secrets without even looking at your secret. API keys and what not. Besides that I find Claude to be generally quite careful and a lot of the times I actually want them to do more things without my permission. It feels like if you have any security related instructions in your claude.md or agents.md files Claude will follow those instructions a lot better than anything else becaude I assume that's how the models have been post trained. I've also had a few times where Claude told me straight up that it caught a sub agent accidentally outputting some dev API key and that I should rotate those keys.
0
u/Zain 5d ago
Our one hard rule is that only one agent ever writes to the repo. Codex and Cursor get used as reviewers and they're read-only, they read the plan or diff and report back, and Claude is the only one that patches files. Even then it has to check each finding against the actual repo before changing anything, so a reviewer saying something is broken never turns into an edit by itself. Doesn't solve secrets or package installs, but it cuts the number of things touching the repo down to one.
0
u/[deleted] 5d ago
--yolo
0
u/kancerus 2d ago
biggest problem? thinking repo level access means safe access, on trina ax ( im affiliated) the focus is on per user folder permissions so agents only access what that person is allowed to see therefore secrets and .env files lie outside agents scope