Skip to content
redactsure
Book a demo

Explore.

Data Report · RedactSure Research
Chris Sowa · Founder, RedactSure
Published
Last updated

How Do I Keep AWS Keys Away From Claude Code?

Deny ~/.aws and the AWS variables in sandbox.credentials, mask the one key a task must use and name the AWS endpoints it calls in injectHosts, and add a Read deny rule, because the Read tool, MCP servers, hooks and WebFetch run outside the sandbox. Keep a durable key in a store the agent reaches by reference.

A credential reference travels from a browser record through a bounded route to a separate API destination.

A developer with an AWS account ends up with a key pair in the home directory: two strings, long-lived, carrying whatever the signed-in identity can do. An agent working in the same directory becomes a new reader of those strings, and a value the model reads can be repeated in a summary, a commit or a log. Two settings and a host list settle what a sandboxed command may read. They do not touch what the model is shown on a console page where a key is created or listed, because the tools that open a file, a hook, an MCP server or a fetched page run outside the sandbox. The distinction appears on one developer machine with a default profile: one key masked for a task, and the console page where the pair was issued. Two of the three routes are closed by settings the developer already has. The third needs a control the harness does not provide, because the page is not a command and no sandbox setting reaches what it draws. A key pair that never expires is worth more to whoever reads it than the task it was issued for, and a console page puts it in front of the model in one screen.

Key findings

  • For an AWS key to stay out of what a model reads, the value on the rendered page has to be replaced with a consistent token such as AWS_KEY_001 before any model sees it, and a sandboxed command has to work from a sentinel rather than from the key itself (Can a Coding Agent Use a Credential It Cannot Read?).
  • It would also require a named person approving the use of a masked key and a record of what the model received, because a value that resolves at a proxy is still a key that somebody spent (What Is Least Exposure?).
  • The pages reviewed describe deny, mask and the tools that sit outside the sandbox, and none of them describes an approver for a masked key or a per-run record of what the model read (How Do I Keep API Keys Out of Claude Code's Context Window?).
  • Claude Code's sandboxing documentation covers shell commands only, and it places Read, Edit, Write, WebFetch, WebSearch, MCP servers and hooks outside the sandbox, so the deny and mask settings govern a command and not the tool that opens a file (Anthropic, Sandboxing, 2026).
  • AWS's own alternative to a long-lived pair is a temporary credential from a role, which "Returns a set of temporary security credentials that you can use to access AWS resources" and can expire within 900 seconds (AWS, AssumeRole, 2026).
  • GitGuardian's count, reported by Help Net Security, found that commits co-authored by Claude Code "leaked secrets at roughly double the baseline rate," and it counted "24,008 unique secrets exposed in MCP configuration files" (Help Net Security, 2025).

What can Claude Code read on the way to an AWS key?

Three routes reach the same key. The first is the credentials file in the home directory, where a default profile holds a pair. The second is the shell environment, where an access key ID and a secret access key sit for any command that inherits them. The third is a console page in a browser, where a key is created, listed or rotated and where the page itself carries the value. Two of the three are the sandbox's territory, because the deny and mask settings govern what a sandboxed command may read. The third is not, and the scope sentence for it is short: a governed browser environment covers what an agent reads and does on a rendered page, including a console, a dashboard or a settings page, and it does not cover the terminal, the IDE, the local filesystem, direct API calls or MCP. Claude Code is a terminal agent, so the page-level half of this question sits outside its own settings.

The route matters more than the count of settings. A key in the file is readable by anything with filesystem access. A key in the environment is readable by every process the agent starts. A key on a console page is readable by the model as soon as the page renders. A team that configures only the sandbox has closed the first two and left the third open, and the third is the one that produces a fresh key. Can a Coding Agent Read My AWS Credentials File? covers the file route on its own terms.

The durable fix is to stop keeping a key that does not expire. Secrets Manager is the store AWS offers for the same job, and its page says "You replace hard-coded credentials with a runtime call to the Secrets Manager service to retrieve credentials dynamically when you need them" (AWS, Secrets Manager, 2026). A runtime call is a better start than a file, and it still hands the value to whatever process makes the call, which on a developer machine is the agent.

How do you deny ~/.aws and mask the one key the task has to use?

Start with the deny side. In sandbox.credentials, list the path that holds the pair and the environment variables that carry it, and a sandboxed command cannot read them. Two details decide whether the rule holds. The first is where it lives: the sandboxing page says sandbox.credentials is honored from user settings, managed settings and the --settings flag, and ignored in .claude/settings.json and .claude/settings.local.json, so a rule committed to the repository is the one that cannot apply it (Anthropic, Sandboxing, 2026). The second is the Read tool, which the sandbox does not cover at all.

The permission documentation answers the Read tool directly: to block a path for the file tools, "add a Read deny rule for its path," and a .claudeignore file "has no effect," so its entries belong in Read deny rules (Anthropic, Permissions, 2026). The same page adds that deny rules "don't apply to a command that reads files without naming them," such as a recursive grep run from the directory that holds the file, and sends OS-level enforcement to the sandbox (Anthropic, Permissions, 2026). Read together, the two pages give one conclusion: close a path with a rule for the tool that opens it and a sandbox rule for the commands that read it, and put both where the repository cannot edit them.

The mask side is for the key a task must use. Declare the credential as masked, and name in injectHosts the AWS endpoints the task calls, so the proxy substitutes the real value there and nowhere else. Then read the list twice, because an empty list is not an empty scope: the documentation substitutes on every host in network.allowedDomains when injectHosts is empty. Is It Safe to Give Claude Code My GitHub Token? walks the same mechanism on a token, and the shape of the answer does not change with the service.

What do the vendors themselves say?

Anthropic's pages describe three settings and one boundary, and AWS describes what a key should be replaced with. Each is quoted here for what it states about the credential, and the last column of the table is the question a buyer is left holding.

The mask setting is the one the page spells out: with mask, "the sandboxed command sees a sentinel and the local proxy substitutes the real value only on hosts in injectHosts," or on every host in network.allowedDomains when that list is empty (Anthropic, Sandboxing, 2026). The page adds that on macOS a masked credential file cannot be read at all inside the sandbox, which gives deny and mask the same effect there (Anthropic, Sandboxing, 2026).

A third setting, CLAUDE_CODE_SUBPROCESS_ENV_SCRUB, strips credentials from all subprocesses regardless of sandboxing, which covers a build step that inherits the environment without naming a file (Anthropic, Sandboxing, 2026). AWS states the flat version in its IAM guide: "IAM users with access keys are an account security risk" and "Do not provide your access keys to unauthorized parties" (AWS, Access keys, 2026).

Dimension Claude Code, per its documentation What a buyer should verify
Where the settings apply "the sandbox covers shell commands only"; Read, Edit, Write, WebFetch, WebSearch, MCP servers and hooks run outside it Which route the agent uses to reach the key, and whether a rule covers that route
What a masked value does Sandboxed commands see a sentinel; the proxy substitutes the real value only on hosts in injectHosts The full host list, and whether it is empty
Where the rule lives Honored from user settings, managed settings and the --settings flag; ignored in .claude/settings.json and .claude/settings.local.json Whether a file in the repository can weaken the rule
Subprocess environment CLAUDE_CODE_SUBPROCESS_ENV_SCRUB strips credentials from all subprocesses Whether the setting is on, and what it covers
Approver and record not described in the pages reviewed Who approves a use of the masked key, and what record shows what the model read

What does the model receive while a key is masked, and where does it go?

A command that calls AWS with a masked key puts the sentinel on the wire, and "the local proxy substitutes the real value only on hosts in injectHosts," so the model reads a successful call and not the key (Anthropic, Sandboxing, 2026). That is the gain and the limit: the value is not in the model's context, and it is still spent on the model's instruction.

The host list is therefore the scope decision, because a call to a listed host carries the key's full permissions, while a task that assumes a role ends up with "the intersection of the role's identity-based policy and the session policies" (AWS, AssumeRole, 2026). A mask over a key with administrator access is a wide grant with a narrow delivery route, and the two parts have to be reviewed together.

The credential provider is the other shape: it "stores the resulting credentials in the token vault, and provides the agent with the necessary access tokens," so the key stays in the vault and the agent receives a usable token it can spend (AWS, Credential provider, 2026). That is better custody than a file and a different question from what the model read.

The transcript is the place to look. Do Claude Code Transcripts Contain My Credentials? follows the sentinel into the log, and How Do I Let a Coding Agent Use AWS Without Giving It My Access Keys? takes the role-session route from the AWS side.

Who approves a masked key's use, and what record shows what the model read?

The approval and the record sit outside both mechanisms. The sandboxing page describes what a command may read and where a masked value resolves, and it describes no approver for a masked key's use and no per-run record of what the model read, which is the part a sandbox cannot supply (Anthropic, Sandboxing, 2026). The permission rules govern what a tool may do, and a rule that allows a call is not a person approving it.

What the AWS pages give instead is a shorter life. Role chaining limits a CLI or API session to a maximum of one hour, so a temporary credential can still outlast the task that needed it (AWS, AssumeRole, 2026). OWASP's CI/CD guidance is plain about the default: "Prefer using temporary credentials over static credentials" and "Avoid sharing the same set of credentials across multiple contexts" (OWASP, 2026). Duration and scope shrink the loss; neither produces an approval or a record.

The other answer, in the documentation's own terms, is an adapter. Willison's pattern for the same problem constrains the agent's actions so that "Agents can trigger tools, but cannot be exposed to or act on the responses from those tools," which is the shape of an adapter that returns a reference instead of a key (Willison, 2025). The agent names the credential, the adapter uses it, and the model holds a reference such as DEPLOY_REF_001. How Do I Secure the Credentials of a Coding Agent I Built Myself? applies that design to a harness you built.

What does a governed environment change?

A governed environment is a control class that acts where a screen is rendered, before any model reads it. Values chosen by policy are replaced with consistent tokens for the whole run, so a console page that shows an access key renders KEY_001 and the run continues on the token. Real values resolve only at an approved destination, at the moment of an approved action. A named person confirms what is tokenized and approves each consequential action, and the creation of a key on a production account is one. Every screen as tokens, every action and every approval is written to a record that exports to the organization's own monitoring.

For this question it changes the half the sandbox leaves open. The file route is closed by the deny and permission rules above, and the console route is closed at the render layer, because the page never reaches the model with the key on it. The two controls compose: one governs what a command reads, the other governs what a page shows, and a team that configures one has closed one route. RedactSure vs Claude Code: 2026 Comparison & Alternative sets the two designs side by side for a buyer.

Its scope is the rendered page. It does not govern the terminal, the IDE, the local filesystem, direct API calls or MCP, so the AWS variables a command inherits stay the sandbox's job.

What the record shows

A key that never reaches the model cannot be repeated by it, and a value that resolves only at an approved destination is spent where a person meant it to be spent. On a developer machine that means two controls rather than one: a rule for what a command may read and a scope on where the real value may go. Claude Code's pages give the first in detail, through deny, mask and the injectHosts list, and they name the tools that sit outside it, which a team that copies a settings file usually misses. AWS's pages give the second, through a temporary session bounded by a role policy and a session policy. Neither answers who approved a use of the key or what the model read, so the record of a run stays the buyer's own to build. To check the path, name one key, one command and one console page, run the task with a test credential, and compare what the command printed with what the page showed the model.

Methodology and limitations

This page rests on Anthropic's Claude Code sandboxing and permissions documentation, four AWS pages, OWASP's guidance, a press report of GitGuardian's count and one practitioner's analysis. The vendor pages were read as of October 20, 2026, and each Sources line carries its date. Public documentation read in full gives a sound view of where each product applies its control: the sandbox page describes its boundary, and the permissions page the rules beside it.

No product here was tested for this page. "Not described" means the pages listed in Sources, and a release after the read date is outside this account until the check is repeated. Vendor features change, and the page carries its date. Statements about RedactSure describe what it does, and RedactSure is deploying now with enterprise and government customers. The example describes a record type, a key pair on a developer machine with one console page that creates keys, and not an organization.

Whether a configuration meets a contractual, regulatory or audit requirement is for counsel, assessors and the organization's own security and compliance officers. Nothing here replaces a test of its settings against a test key.

Frequently asked questions

How do I keep AWS keys away from Claude Code?

Deny the path that holds the pair and the environment variables that carry it in sandbox.credentials, add a Read deny rule for the same path, and mask any key a task must use so sandboxed commands see a sentinel and the proxy supplies the real value only where injectHosts names a host. Then note what none of that covers: the Read tool, MCP servers, hooks, WebFetch and WebSearch run outside the sandbox. Write the list down, because each addition changes which routes remain.

Does masking a key keep it out of the model's context?

Only for sandboxed commands, and only as a sentinel. A masked credential is replaced on the wire, so a command sees a stand-in while the call still carries the key's full permissions to the hosts on the list. The value does not appear in that command's output, which keeps it out of the transcript for that route. A file the Read tool opens, or a server that returns the key, puts the real value into the context with no masking involved.

What does Claude Code read outside the sandbox?

Read, Edit, Write, WebFetch, WebSearch, MCP servers and hooks, by the sandboxing page's own list. Those routes are not governed by a deny or mask rule, so a key in a file the Read tool opens, or in a server's response, reaches the context as itself. The permission page adds that file rules do not stop a command that reads files without naming them, which is why the sandbox rule is needed beside them.

Who approves a masked key's use?

No page reviewed describes one. The sandbox decides what a command may read and where a masked value resolves, and the permission rules decide what a tool may do. Neither describes a person approving a single use of the key, so approval sits with whatever wraps the run: the person who starts it, a policy on the role it assumes, or an environment that holds the value and asks before releasing it.

What record shows which key the agent used?

None of these settings produces one. A sentinel in a transcript shows that a masked credential was used and not which value it stood for, and a role session shows the role, its duration and the policies that bounded it. An audit needs a record of what the model read on each page and which person approved each use, and that record has to come from the layer that holds the value.

Is a temporary AWS credential enough on its own?

It is the better half. A session from a role returns temporary credentials bounded by the role policy and the session policy, and it expires, which is the direction the CI/CD guidance takes when it prefers temporary credentials over static ones. It still hands the agent a usable token, and role chaining caps a CLI or API session at an hour, so its value depends on the scope given to the role. Read the role's policy before trusting the session.

About the author

Chris Sowa is a founder of RedactSure and a former CEO of an AI company; he started it years before ChatGPT existed. He previously led AI at Accenture, served as Global VP of Strategy & Innovation at Schneider Electric, was CCO of Sovos, and spent more than a decade at Oracle, with earlier roles at SAP and IBM.

How RedactSure Keeps an AWS Key Off the Page an Agent Reads

An AWS key pair outlasts the task it was made for, and the rules above govern commands, not the console page that shows the next key.

The environment that enforces this is built by RedactSure, an AI agent controls, governance and data protection company.

Before: the agent opens the IAM page that creates an access key, and the model reads the new pair as the page shows it. Inside the governed environment: the page renders KEY_001 in place of the pair, and the real value resolves only to the endpoint a named person approved.

RedactSure is deploying now with enterprise and government customers. GitGuardian's count found commits co-authored by Claude Code "leaked secrets at roughly double the baseline rate."

Everyone else controls where data can go. RedactSure controls what the AI can see.

See it on your own workflow

A key created on a console page is readable as soon as the page renders, and no settings file closes that route. Bring the AWS task you delegate and see, with test values, what the model reads on that page. Book a demo

Book a demo

Book a demo

Having trouble? Open the booking page or email us.