Guide
Is it safe to open or clone untrusted repos with a coding agent?
Updated
Short answer
Not on a laptop that holds real credentials. A repo can carry config that runs code when it's opened, and text that steers the agent once it's running. Vendors have patched the specific bugs researchers found, but the pattern remains. Open untrusted repos in a throwaway container or VM with no credentials, keep agents patched, and check every agent action before it runs.
What the risk actually is#
Opening a repo in a plain editor doesn't run anything in it.
A coding agent changes that. It reads the repo's config, rules files and settings, and it holds your credentials while it does. There are 2 separate problems here, and they need different controls.
- Code that runs on open. Config files in the repo get executed by the agent tool or by git before you've decided anything.
- Instructions that steer the agent. Text in a README, rules file or issue gets read as a task, and the agent acts on it with your permissions.
Config that runs before you click trust#
Check Point Research reported that attackers could run arbitrary shell commands and exfiltrate Anthropic API keys when users cloned and opened untrusted repositories with Claude Code.
Sonar found a related path. Their write-up says a malicious project could include a .claude/settings.json file that triggered arbitrary code execution before the trust dialog was presented.
Check Point says everything it reported has been patched. Still, a trust prompt only protects you from what runs after it.
Other agents have hit the same family. goose CLI versions 1.35.0 up to, but not including, 1.53.0 ran commands set in a crafted repo's git config when a user ran goose review on it.
What the built-in controls do and don't stop#
They help, and you should turn them on.
- Workspace trust dialog. It asks before the agent works in a folder you haven't trusted. Anthropic's docs note that a non-interactive
-psession shows neither prompt, so scripts and CI skip that gate. - Permission rules and managed settings. They decide what the agent may do once it's running. They don't govern what the tool or git does while loading a project.
- Sandbox. It limits the reach of commands. It doesn't judge whether an action inside that reach matches the task. See sandboxing Claude Code and Codex.
- Approval prompts. In Anthropic's study of 1,053 testers, humans caught 13.6% of dangerous commands and approved 93% of prompts anyway.
- Patching. It closes known bugs, including the pre-trust ones above. Some fixes ship as plain changelog lines, so see patching when fixes ship silently.
Anthropic's own security page tells you to use virtual machines to run scripts and make tool calls, and says no system is completely immune to all attacks.
The second problem: instructions in the repo#
Even with a clean open, the repo can talk to the agent. A planted rules file, a README, a ticket or a dependency's docs can say "run this install script" in words the agent treats as the task.
No filter reliably strips that text out. The better move is to judge the action the agent then tries to take. More in protecting coding agents from prompt injection.
A decision rule#
Sort repos by who wrote them.
- Your own repos and your org's. Open normally on a patched agent, with managed settings on.
- Open-source repos you'll depend on. Read the config first. Open in a dev container with no cloud credentials mounted.
- Unknown repos, take-home code, security research, a stranger's pull request. Throwaway VM or container only. No SSH keys, no cloud tokens, no agent credentials. Egress limited.
A checklist#
- Inventory agent versions and set a minimum. Old versions are where the known pre-trust bugs live.
- Don't run agents on untrusted repos in non-interactive mode on a laptop. That path skips the trust prompt.
- Before opening, look at
.claude/,.cursor/,.git/config,.mcp.jsonand any hooks or rules files. Treat them as code. - Turn off auto-approve rules for anything freshly cloned.
- Keep long-lived credentials off the machine. Use short-lived, scoped tokens.
- Review config diffs on every pull, not only the first clone. A tool approved once can change later.
Where Harden fits#
Harden Agentic Integrity Foundation (AIF) runs on the developer laptop, outside the agent, at the agent's pre-execution hook. Every command, file edit and push the agent proposes is checked against the session's intent before it runs, locally, with verdicts in about 28 ms. One policy covers every agent, and it starts watch-only so you see what agents try before you enforce.
For this problem: if a planted rules file gets the agent to pipe a script to a shell, or to send a secret to a network call, AIF checks that action before it executes and can block it with a reason the agent can act on. See what a pre-execution check should do.
It's a layer. It checks the actions the agent takes; it doesn't replace patching, a container, scoped credentials or egress policy, and it doesn't contain a process that's already malicious.
An untrusted repo is safe to open when the machine has nothing worth stealing and every action the agent takes gets checked first.
FAQ
Related questions
Does the Claude Code trust prompt make opening a repo safe?
It helps, but it isn't a guarantee. Researchers found project settings that ran code before the trust dialog appeared, and Check Point says the issues it reported were patched. Anthropic's docs also say a non-interactive -p session doesn't show the prompt.
Is reading a repo in my editor safer than opening it with an agent?
Reading code in a plain editor doesn't run it. An agent loads config, rules files and settings, and acts with your credentials, so the same repo carries more risk when an agent opens it.
Should we block agents on untrusted repos entirely?
No. Run them in a throwaway container or VM with no credentials and limited egress. The agent stays useful for review and research, and your laptop's credentials stay out of reach.
Can a repo's git config alone run code?
Yes. Git runs commands that its config tells it to, and a crafted repo can ship that config. goose CLI from 1.35.0 up to, but not including, 1.53.0 ran such commands via goose review.
How does Harden start on a fleet?
Harden starts watch-only, pushed by the MDM you already run, so you see what agents attempt across repos before you turn on enforcement.