---
title: "Network rules and secrets for AI agents: the patterns agent products settled on in 2026"
description: "An agent that can read a secret and reach the internet can be talked into sending one to the other. How agent products now limit the network and keep keys out of the model's reach, and how to apply the same patterns to your own agents."
url: "https://www.promigence.ai/blog/agent-network-rules-and-secrets-2026"
site: "Promigence"
---

# Network rules and secrets for AI agents: the patterns agent products settled on in 2026

_Harshraj, 26 November 2026_

## How do AI agents leak secrets?

The main security risk with AI agents is a pair of permissions held at once: the agent can read something sensitive, and it can reach a place to send it. Agent products in 2026 handle that pair in two ways. They limit the network, by turning it off or allowing only named hosts, and they keep secrets out of the model's reach, by removing them before the agent runs or by adding them to requests outside the agent's view. Neither control needs the model to behave. Both hold when it does not.

## Why the network and the secrets are one problem

An agent reads a lot of text it did not write: issue comments, web pages, documentation, test output, the contents of a dependency. Any of it can carry instructions. A sentence hidden in a README that says to print the environment variables and post them to a URL is enough, if the agent follows it.

Anthropic described the pairing precisely when it added sandboxing to Claude Code in October 2025: "effective sandboxing requires both filesystem and network isolation." Without network isolation, "a compromised agent could exfiltrate sensitive files like SSH keys." Without filesystem isolation, the agent could change the rules that limit it. Each control covers the other's gap.

The OWASP GenAI Security Project puts the same idea in general terms. Its entry on Excessive Agency lists the root causes as too much functionality, too many permissions and too much autonomy, and its first advice is to "limit the extensions that LLM agents are allowed to call to only the minimum necessary." For an agent that runs code, the network and the secrets are the two permissions that matter most.

## Pattern one: the network is off until a task needs it

The simplest rule is the strongest. If the agent's work does not need the internet, it should not have it.

OpenAI's Codex applies this by default to its cloud tasks: setup scripts can reach the internet to install packages, but "during the agent phase, internet access is off by default." Claude Code's cloud environments offer four levels, from no network at all to any domain. In between, the Trusted level reaches an allowlist of package registries and cloud SDKs, plus GitHub, and nothing else. GitHub's Copilot cloud agent runs behind a firewall that is strict by default.

The split between setup and work is the useful insight here. Installing dependencies needs the network. Reading code, editing it and running tests mostly does not, once the dependencies are in place. Give the two phases different rules and the agent loses most of its ways to leak without losing any ability to do the task.

## Pattern two: when the network is on, it is a list of hosts

Some tasks need the network: an agent that calls an API, fetches documentation or pushes a branch. The answer there is an allowlist, enforced outside the agent.

Anthropic's approach routes the agent's traffic through a proxy that "enforces restrictions on the domains that a process can connect to", and it released that sandbox runtime as open source so other teams could use it. Claude Code's Custom level lets a team list its own hosts, with wildcards for subdomains. Sandbox providers do the same at the sandbox level: block the network entirely, or allow outbound traffic only to the addresses or domains you list.

Two details decide whether an allowlist helps. The first is where it is enforced: a rule the agent can edit is a suggestion. The second is how broad the entries are. Allowing a whole code-hosting site lets an agent push to any repository on it, including one an attacker controls, so the narrower entry is better wherever the tool allows it.

## Pattern three: the agent uses secrets it cannot read

The hardest case is an agent that needs a credential to do its job, such as an API key for a service the task calls. Putting the key in an environment variable works and is dangerous: whatever can read the variable can print it.

Products have converged on three answers. The first is to remove secrets before the agent starts, which is Codex's rule: secrets are "only available to setup scripts", and "for security reasons, secrets are removed before the agent phase starts." That suits keys needed to install private packages, and it does nothing for keys the task itself needs.

The second is to attach the secret to outgoing requests from outside the agent. Claude Code's cloud environments store network secrets "that sessions use without seeing them", sent with requests to the hosts you name. The agent makes the call, the request carries the key, and the agent never holds it.

The third is to give the agent a credential so narrow that leaking it costs little: a token scoped to one repository, one bucket or one action, set to expire after the task.

## Pattern four: a person approves the irreversible steps

A few actions cannot be undone: a payment, a deletion, a message to a customer, a merge to the main branch. OWASP's advice is direct: put a human in the loop, so that a person approves high-impact actions before they are taken. The MCP specification asks the same of any application that calls tools, that it "obtain explicit user consent before invoking any tool."

Approval prompts have a cost. Too many and people stop reading them, which is why Anthropic framed sandboxing as a way to ask less often: in its own use, sandboxing "safely reduces permission prompts by 84%". The pattern that works is to sandbox everything, keep the network and secrets tight, and save the human approval for the few actions that reach outside the sandbox and cannot be reversed.

## Applying the patterns to your own agents

Teams that run open source agents, or build their own, get none of these defaults for free. A practical order of work looks like this.

Start with no network inside the sandbox, and open it only for the setup step. Most of the risk disappears there, and so does surprisingly little capability.

Next, list the hosts each kind of task needs and enforce that list outside the agent's reach. Review the list the way you review firewall rules, because that is what it is.

Then move every secret out of the agent's environment. Use setup-only secrets for installs, attach the rest to requests from outside the sandbox, and scope whatever remains to the task.

Last, log what the agent reached and what it ran, and decide which actions need a person. When something goes wrong, the log is how you find out what the agent did, and how you show a customer what it did not do.

All of this assumes the agent runs somewhere separate from your own systems. A sandbox per task, created for the task and deleted after it, is what turns these rules from advice into limits. The [Run AI-written code safely guide](https://www.promigence.ai/docs/guides/run-ai-written-code-safely) shows how Promigence sandboxes apply network and secret settings in practice.

## FAQ

### How do AI agents leak secrets?

Usually through instructions hidden in content the agent reads, such as a web page, an issue or a file. If the agent can read a secret and reach the internet, those instructions can tell it to send one to the other. Limiting the network and keeping secrets out of the agent's reach closes that path.

### Should AI agents have internet access?

Only as much as the task needs. Many coding tasks need the network to install dependencies and not afterwards, so a common pattern opens the network during setup and closes it, or limits it to named hosts, while the agent works.

### What is an allowlist for an AI agent?

It is the list of hosts an agent may connect to, enforced outside the agent, often by a proxy. Requests to anything else are refused, so injected instructions cannot send data to an attacker's server.

### How can an agent use an API key without seeing it?

The key is added to the agent's outgoing requests by something outside the agent, for the hosts you name. The agent makes the call and gets the result, but the key never appears in its environment, so it cannot be printed or leaked.

## Sources

| Source | What it supports | Read |
|---|---|---|
| [Anthropic engineering: Claude Code sandboxing](https://www.anthropic.com/engineering/claude-code-sandboxing) (20 Oct 2025) | filesystem plus network isolation, the domain proxy, the open source runtime, 84% fewer prompts | 25 Oct 2026 |
| [OWASP GenAI: LLM06:2025 Excessive Agency](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/) | root causes, minimum access, human approval | 25 Oct 2026 |
| [OpenAI Codex: cloud environments](https://learn.chatgpt.com/docs/environments/cloud-environment) | internet off by default in the agent phase; secrets removed before it | 25 Oct 2026 |
| [Claude Code: cloud environments](https://code.claude.com/docs/en/cloud-environments) | the four network levels; network secrets used without being seen | 25 Oct 2026 |
| [GitHub Docs: customize the Copilot cloud agent environment](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/customize-the-agent-environment) | the firewall | 25 Oct 2026 |
| [MCP specification, 2026-07-28](https://modelcontextprotocol.io/specification/latest) | user consent before any tool runs | 25 Oct 2026 |

