Updated: 2026-10-31.
You ask your coding agent to sort the open issues in a public repository. Most of them are ordinary bug reports. One of them also contains a paragraph written for the agent, not for you: it asks the agent to collect material from your private repositories and post it somewhere public. The agent reads that text with the same attention it gives your request, and it has the tools to obey.
This is not a hypothetical design flaw. In May 2025, researchers at Invariant Labs showed this sequence with the official GitHub server for the Model Context Protocol (MCP), the standard many agents use to connect to outside tools. In a demonstration with their own repositories, a crafted issue led an agent to copy private-repository data into a public pull request. They described it as a problem in how the agent system was put together, not a bug in the server's code. Invariant Labs
This guide helps you set up one agent workspace on the assumption that the agent will sometimes be fooled. The goal is a workspace where a fooled agent finds little worth taking and has no easy way to send it anywhere. The examples use Claude Code, and the agent download contains the complete configuration.
Why a better prompt cannot fix this
A language model receives your instructions and the content it reads as one stream of text. Nothing in the model marks one part as a command and another as mere data. Researchers named the resulting attack indirect prompt injection in 2023: an attacker places instructions in a web page, document or other content that an application will later give to the model. Greshake et al.
Security agencies and standards bodies now say plainly that this problem has no complete fix. The UK National Cyber Security Centre (NCSC) writes that prompt injection may never be mitigated as fully as SQL injection can be, because the model has no built-in boundary between data and instructions. OWASP, which lists prompt injection first among risks to language-model applications, says it is unclear that any fool-proof prevention exists. Anthropic's own security page for Claude Code states that no system is completely immune. NCSC, OWASP LLM01:2025, Claude Code security
Filters do not change that conclusion. A list of banned phrases fails because an attacker can rephrase the same request in endless ways. Some products offer to detect injection; NCSC advises caution with any that claim to stop it, and to prefer those that explain how they reduce it. Simon Willison, an independent developer who has written about this attack class since he named it, puts the point sharply: a detector that catches 95% of attacks would be a failing grade in web application security. NCSC, Willison
So no setting in this guide will stop your agent from being fooled. What the settings can do is limit what a fooled agent can read, change and send. Large vendors work the same way: Microsoft's security team writes that its defences do not depend on blocking every injection, but on keeping a successful one from causing harm. Microsoft MSRC
Three questions for each workspace
Willison describes a "lethal trifecta": an agent that has private data, reads untrusted content and can communicate externally is open to data theft. The danger comes from having all three in the same place. That gives you a quick test for a workspace. Willison
| Question | Typical answer for a coding agent | What narrows it |
|---|---|---|
| What private data can it reach? | Your home directory, keys, tokens, other projects | A workspace that holds only this project; reads outside it refused |
| What untrusted text will it read? | Issues, web pages, dependencies, tool results | Fewer and narrower tools; review before you trust a project folder |
| How could it send data out? | Shell network access, web fetches, MCP tools that post | A network allowlist that starts empty; approval for pushes and posts |
For most coding work you cannot remove untrusted content: reading code and documentation written by others is the job. The practical choices are in the first and third rows. OWASP's guidance on "excessive agency" points the same way. It traces damage to three causes, namely too much functionality, too many permissions and too much autonomy, and recommends narrow tools, least-privilege credentials and human approval for actions with a large effect. OWASP LLM06:2025
The same pattern appears in another disclosed case. Researchers at Legit Security hid instructions in project content that made GitLab's Duo assistant leak private source code in a proof of concept; GitLab fixed the rendering of external image and form tags that carried the data out. Like the GitHub demonstration, it combined private data, untrusted text and a way out. Separately, Microsoft rated a Microsoft 365 Copilot information-disclosure flaw, CVE-2025-32711, as critical; its advisory lists no customer action and no known exploitation. Legit Security, MSRC CVE-2025-32711
Build a workspace with little to steal
Start with a directory that contains one project and nothing else. Do not start the agent in your home directory, where it can see every project, your shell history and your configuration. Put the project under Git so that you can review every change the agent makes with an ordinary diff.
Keep secrets out of that directory. A .env file, a deploy key or a cloud token
inside the workspace is exactly what an injected instruction will ask for. If
the project needs a token, create a new one with the narrowest scope and the
shortest expiry the service allows, and write down what it can do. A token that
can only read one repository limits the damage even if it leaks.
Claude Code can then make its file tools refuse reads outside the working
directory in every permission mode, and, when the sandbox is on, keep shell
commands out of your home directory and other user folders. Shell commands can
still read system locations such as /etc. Explicit deny rules for .env files and credential folders add a
second check. One gap remains: commands inherit the environment variables of
the terminal that starts the agent, so launch it from a shell that holds no
tokens, or ask Claude Code to scrub credentials from the environment it gives
to commands. The scrub leaves GitHub tokens in place, so start without them.
Claude Code settings,
Sandboxing,
Environment variables
Keep the rules outside the project
An agent's settings are only as trustworthy as the file they come from. A cloned
project can carry its own .claude/settings.json, its own hooks and its own
.mcp.json server list. Claude Code holds back a project's allow rules until you
accept its trust prompt, but hooks and environment settings from a repository can
run as soon as a parent folder is trusted. Read those files before you trust a
project you did not write.
Permissions and workspace trust
The download therefore keeps the protective policy in a separate file outside the workspace and passes it to Claude Code at launch. Settings passed this way rank above the project's own files. One of them, turning off the sandbox's "retry outside the sandbox" option, also makes Claude Code ignore repository settings that would loosen the sandbox, such as extra allowed domains or commands excluded from it. The same file sets the session to start in Manual mode, in which Claude Code asks before edits and most commands. Interactive sessions otherwise start in auto mode, where a classifier model reviews actions instead of you. Settings precedence, Sandboxing, Claude Code security
Treat command rules as signs, not walls
Permission rules are the first thing most people reach for: deny curl, ask
before git push. They are useful, and the download includes them. But a rule
for a shell command matches the text of the command, not the program behind it.
Claude Code's own documentation shows that a deny rule for curl does not stop
/usr/bin/curl or the same call wrapped in sh -c. A script in any language can
open a network connection without naming a tool at all.
Permissions
The operating-system sandbox is the layer that does not depend on wording. When it is on, every shell command and the processes it starts run inside limits that the kernel enforces: writes only in the workspace and a temporary directory, and no direct network route. Network traffic must pass a local proxy that compares each hostname with your allowed list. The download starts that list empty, makes the proxy refuse other hosts instead of asking, and stops Claude Code from starting at all if the sandbox cannot run. On Linux the sandbox needs two small programs, bubblewrap and socat; if they are missing, installing them needs administrator rights. Sandboxing
Two limits apply here. First, an allowed domain is a possible exit. A broad entry such as a large code-hosting site can carry data out just as well as an unknown server, and the proxy checks hostnames without inspecting encrypted traffic. Add the specific hosts a task needs, one at a time. Second, the sandbox covers shell commands only. Claude Code's file and web tools follow permission rules instead, and hooks and local MCP servers run with your full user access. Sandboxing
Other agent harnesses document similar pairs of controls. OpenAI's Codex, for example, separates sandbox modes that limit file and network access from an approval policy that decides when to ask the user. This guide covers only Claude Code. Codex sandboxing
Connect fewer tools, with smaller keys
Each MCP server adds tools the agent can call, and each tool that can post, send or write somewhere outside your machine is another way out. A local MCP server is also a program that runs on your computer outside the sandbox. The MCP specification's security guidance asks clients to show the exact command that starts a local server, to require consent and to run servers with minimal privileges; it also forbids passing user tokens straight through to other services. MCP security best practices
List the servers your agent can load and remove the ones this project does not
need. A project's .mcp.json does not show every server: some come from your
user configuration or from plugins. For each server you keep, record where it
came from and what its token allows. Anthropic reviews connectors in its
directory against listing criteria, but its security page says it does not
audit or manage MCP servers.
Claude Code security,
Claude Code MCP
Keep a log you will actually read
You cannot respond to what you cannot see. NCSC recommends logging enough to spot suspicious activity, including tool calls, because an attacker usually needs several attempts. The download adds a small hook that writes one line for each tool call (time, session, tool and input) to a private file outside the workspace. Hooks run outside the sandbox with your access, so keep the script short and readable. NCSC, Hooks
A log nobody opens protects nothing. Look through it after any session in which the agent read content you do not control, and at least weekly. Failed or refused calls are worth a second look: they show what the agent tried, not only what it managed. Remember that the log can contain whatever the agent wrote or ran, so treat it as private.
Check that the controls are on
The download ends with a short self-check that sends nothing to an outside server when the controls work. You ask the agent to write a file in your home directory, to reach a web address through the proxy and around it, to read a dummy secret file, and to summarize a document with one planted instruction. Each request except the summary should fail or be refused in a specific way; the summary must not lead to the planted action. The log should record each attempt.
Be clear about what a pass means. It shows that the sandbox, the rules and the log are active in this workspace today. It does not show that the agent resists prompt injection: one harmless test instruction proves very little about the next, better-written one. Run the check again after you update Claude Code or change the policy, because a quiet change in either can reopen a gap.
What this setup does not cover
This workspace narrows the damage from one class of attack on one machine. It does not make untrusted web browsing safe; for that kind of work Anthropic recommends a virtual machine, and its documentation describes running the whole Claude Code process in a container or its separate sandbox runtime. It does not review the code the agent writes, and it cannot protect secrets you paste into the conversation. Claude Code security, Sandboxing
The controls also cost something. An empty network allowlist breaks package installs until you add the hosts they need, and Manual mode asks more questions, including before every web fetch and search. Approve a web domain once rather than telling Claude Code not to ask again: each saved domain is another possible exit. Each exception you add is a decision about the three questions above. If the setup gets in your way, you can return to normal behaviour at once by starting Claude Code without the policy file; the download's rollback section removes the rest.
Start with the workspace you use most for content you do not control, such as issue triage or dependency review. Apply the policy, run the self-check and read the first day's log.
Keep the guide with your own notes.
Download the complete Markdown version