Guide
How do I stop AI coding agents from sending source code or credentials off the machine?
Updated
Short answer
Check every outbound action on the developer's machine before it runs. A coding agent sends code out with ordinary actions: curl, a git push to a new remote, a package publish, an MCP call or a DNS lookup. Blocking the network breaks the work. Judge each action against what the session is doing, and block the ones that carry secrets or code somewhere the task never needed to go.
How agents actually send code out#
None of this needs malware. The agent already holds the developer's credentials and can run shell commands, so getting data off the machine takes one ordinary line.
The common paths:
- curl or wget with a secret in the URL, header or body.
- git push to a new remote, or to a fork the attacker owns.
- Package publish, which ships whatever is in the directory to a public registry.
- An MCP tool call that passes file contents to a third-party server as an argument.
- DNS lookups with data encoded into the subdomain. A high-severity Claude Code vulnerability that was patched in June 2025 did exactly this: prompt injection was used to exfiltrate API keys via DNS subdomain encoding.
Developers run every one of these on a normal day. The same text is fine in one session and a leak in another.
How prompt injection triggers it#
Most of these leaks start with text the agent reads, not with anything the user asked for. OWASP defines prompt injection as prompts that alter "the LLM's behavior or output in unintended ways."
In a coding agent, that text can sit in a repo file, an issue or a dependency. HiddenLayer showed exfiltration of an OpenAI API key via curl in Cursor, despite curl being explicitly blocked on the Denylist.
More on this in protecting coding agents from prompt injection.
What the built-in controls stop, and what they miss#
They remove a lot of risk. Turn them on.
- Permission rules match command text. Claude Code's docs call Bash patterns that try to constrain arguments fragile:
Bash(curl http://github.com/ *)won't match options before the URL, a different protocol, redirects or a variable holding the URL. Treat them as a first filter, not a boundary. - Sandbox network allowlist. In Claude Code, a sandboxed command has no direct route to the network, and a built-in proxy enforces your allowlist on the requested hostname. That's real containment. The same docs say the proxy, by default, doesn't terminate or inspect TLS traffic.
- Approval prompts. Anthropic reports that users accept 93% of manual prompts anyway. A prompt that gets clicked through that often catches very little.
Why egress rules miss encoded or chunked data#
An egress rule answers one question: is this destination allowed? It doesn't read the payload.
So an allowed host can still carry a secret. Base64 in a query string passes. So does a private key split across several small requests, or a repo posted to a paste site someone allowlisted for a good reason. Where the proxy doesn't inspect TLS, it never sees any of it.
DNS shows the same gap from another side: the request is a hostname lookup, and the secret is the hostname.
The workable approach is to enumerate sinks, not attacks. The ways a value can leave a machine are few and stable. The ways an attacker can phrase the request are open-ended.
Why the check has to be local#
A check that ships the command or file to a cloud service to decide whether it's safe has already moved it off the laptop. Your code and credentials leave the machine to get approved.
The check needs to run on the machine, read the actual bytes and decide there. It also has to sit outside the agent, so a hijacked agent can't talk its way past it or drop it when the session compacts its context.
A decision rule you can use#
For each outbound action, ask three things:
- Where is the value going? A new remote, a public registry, an unknown host or an MCP server not on your list needs a reason.
- What is it carrying? Judge the content, not the filename. A
.pemholding a public certificate is fine; one holding a private key isn't. - Does the task need it? Pushing a feature branch to the repo's existing origin fits. Pushing the same tree to a new remote doesn't.
Then stack the cheap controls underneath: scoped, short-lived credentials, a sandbox with a domain allowlist, and an MCP allowlist. See secure MCP servers for coding agents and stop coding agents leaking secrets.
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 is checked against the session's intent before it runs.
AIF parses the command and follows the data from where it came from to where it's going, decoding base64 and hex first. A secret reaching a network call is a dangerous flow, and AIF blocks it.
Nothing leaves the machine to make that decision, and verdicts take about 28 ms. If a call is blocked, the agent gets the reason and can retry a safe way.
Every decision is recorded. When someone asks what an agent sent and where, you have Records to answer with, and you can export them to your SIEM. It starts watch-only, so you see what agents try before you enforce, and one policy covers every agent.
The limits: it's a layer, not a perimeter. Exfiltration spread across several separate calls is the hard case, and it doesn't replace least privilege, scoped credentials or egress policy. See what a pre-execution check should do.
FAQ
Related questions
Can I just block curl and wget for coding agents?
It helps, but it won't hold alone. Claude Code's docs call Bash patterns that constrain arguments fragile: options before the URL, redirects or a variable can slip past. Agents also have other routes out: git push, package publish, MCP calls and DNS.
Does a sandbox network allowlist stop exfiltration?
It stops connections to hosts you haven't allowed, which is a big reduction. It doesn't read what goes to an allowed host, and by default Claude Code's proxy doesn't inspect TLS traffic.
Why can't a cloud service do the check?
Sending the command or file to a cloud service to be judged is itself a transfer of code or credentials off the laptop. A local check reads the bytes on the machine and decides there.
How do I investigate after an agent sent something out?
You need a record of each action, the verdict and the reason, kept outside the agent. Harden records every decision and can export Records to a SIEM such as Splunk or Coralogix.
Can I try this without blocking anything?
Yes. Harden starts watch-only, logging what agents try without enforcing. Once you've seen the real traffic, you turn on blocks for the flows you care about.
Sources
- Sandboxing - Claude Code Docs
- Configure permissions - Claude Code Docs
- How we built Claude Code auto mode (Anthropic)
- How Hidden Prompt Injections Can Hijack AI Code Assistants Like Cursor (HiddenLayer)
- New Claude Code Attack Allows Attackers to Take Full Control of Developers' Systems (Cybersecurity News, Guru Baran)
- LLM01:2025 Prompt Injection (OWASP GenAI)