SHEET 03blog/coding-agents-without-your-keys/ REVISED 

How to run coding agents without handing them your keys

Coding agents can read your SSH keys, cloud credentials and tokens by default. How to sandbox them, keep secrets outside the sandbox and scope every token.

Published
Length
10 min read
Tags
  • security
  • ai-agents
  • secrets
  • developer-tools

Keep credentials out of anything the agent controls. Run the coding agent in a sandbox that can’t read ~/.ssh, ~/.aws or your shell’s tokens. Let a proxy outside the sandbox add a narrow, short-lived credential only on requests to hosts you’ve approved. Do the high-privilege steps, such as pushing, deploying and publishing, in a separate process the agent can’t reach. Instructions in the prompt aren’t a control.

Why can’t you just tell the agent to leave secrets alone?

Because a prompt is input, and the agent reads plenty of input you didn’t write. Issues, READMEs, dependency source, web pages and MCP tool output can all carry instructions. If the agent can read a secret and also reach the network, one injected paragraph is enough to send that secret somewhere else.

Simon Willison’s “lethal trifecta” describes the dangerous combination: access to private data, exposure to untrusted content, and the ability to communicate externally. A coding agent on a developer laptop has all three by default. His advice is to avoid that combination entirely, and the rest of this post is about removing one or two of the three.

Two incidents from this autumn show what’s at stake. In the breach behind Cursor’s backdoored Claude Code extension, Cursor’s November 13 update says the attacker used an access key Cursor had issued to Fireworks AI to copy stored coding-agent traces. A small number of those traces held credentials that “had not been redacted”, and the attacker used them to reach other Cursor systems (BleepingComputer’s report has the same chain). Credentials that pass through an agent session can end up in logs and traces at companies you’ve never thought about.

Once a secret leaks, someone uses it quickly. On November 5 Microsoft described an AI agent going “from searching for the client secrets in GitHub to exfiltrating data from Azure Key Vault in five minutes.” That was one observed case, but it shows that rotating a leaked key the next morning can be far too late.

What can a coding agent read by default?

Usually everything you can read. The defaults differ between tools, so check yours rather than assuming.

Claude Code’s sandboxing docs are explicit. The sandbox is off by default. When it’s on, sandboxed commands can write only to the working directory and temp, and network traffic goes through a proxy whose allowed-domain list starts empty. Reads are a different story: sandboxed commands can read “most of the machine, including credential files such as ~/.ssh and ~/.aws/credentials”, and they inherit environment variables “including any secrets in its environment”. There’s no built-in credential deny list. The sandbox also doesn’t cover the Read and WebFetch tools, which follow permission rules, or hooks and local MCP servers, which run with your full access.

OpenAI’s Codex is stricter about the network. Its approvals and security page says that by default “the agent runs with network access turned off”, and writes are limited to the workspace.

Layer What it stops What it doesn’t stop
Prompt instructions Nothing reliably Anything
Agent permission prompts Actions you notice and refuse Actions you approve on autopilot, and code that plugins run outside the agent’s tool calls
Built-in sandbox (Seatbelt, bubblewrap) Writes outside the project, unapproved hosts Reads of secrets you didn’t list, hooks and MCP servers
Container or dev container Access to host files you don’t mount Kernel escapes, anything you mount or pass in
MicroVM or throwaway VM Kernel-level escape to your host Whatever credentials and network you give the VM
Credential proxy The agent ever holding the real secret Misuse of the secret on hosts where the proxy injects it
Narrow, short-lived token Damage beyond the token’s scope and lifetime Damage within its scope

Which sandbox should you use?

Use one you’ll actually leave switched on. For a trusted agent working on your own code, the built-in sandbox or an OS-level tool like nono is enough. For untrusted repositories or runs with permission prompts skipped, use a microVM.

Kudelski Security compared four tools on November 23, 2026, testing nono v0.76, Docker Sandboxes v0.50.0, Microsandbox v0.7.11 and OpenShell v0.1.8:

Tool Isolation Credential handling Score
nono OS-level: Landlock and seccomp on Linux, Seatbelt on macOS; shares the host kernel; Windows only via WSL2 Injects from 1Password, Bitwarden, env vars or a command; scopes to domain and endpoint; sandboxed OAuth logins 4/5
Docker Sandboxes A microVM per agent, with a Docker daemon inside Injects into HTTP headers and Basic auth; scopes by domain 4.5/5, closed source
Microsandbox MicroVM on libkrunfw, runs any OCI image Env vars and direct values; scopes by domain; no vault integration 4/5
OpenShell Several backends: Docker, Podman, Kubernetes, microVM, Windows MXC Widest injection options, including AWS SigV4 signing; scopes by endpoint 4.5/5, “still early”

The author’s conclusion is the one to remember: “the best sandbox is the one that stays enabled.” If none of these fits, turn on your agent’s built-in sandbox.

A rough decision guide:

  • Your own repo, you’re watching: the agent’s built-in sandbox, or nono, with credentials denied or masked.
  • Unattended runs, or permission prompts skipped: a dev container or microVM, with no host credential files mounted. Anthropic’s dev container docs warn that with --dangerously-skip-permissions, a container doesn’t stop a malicious project from exfiltrating anything inside it, “including the Claude Code credentials stored in ~/.claude”.
  • A repo or task you don’t trust: a throwaway VM or microVM with an egress allowlist, destroyed afterwards.
  • Agents running in the cloud: a managed per-session VM. Since November 12, AWS’s next-generation AgentCore Runtime runs every session “in its own hardware-isolated Firecracker microVM”, with up to 8 vCPU and 32 GB.

How do you give an agent a credential it can’t read?

Give it a placeholder. A proxy outside the sandbox swaps the placeholder for the real value on outbound requests to approved hosts. The agent’s code and logs only ever contain the placeholder.

nono calls these phantom tokens: “The sandbox receives a phantom GH_TOKEN; the real credential stays with the supervisor.” Claude Code does the same thing with sandbox.credentials entries set to mask. This is the user-level config I’d start from, in ~/.claude/settings.json:

{
  "sandbox": {
    "enabled": true,
    "allowUnsandboxedCommands": false,
    "network": {
      "tlsTerminate": {},
      "allowedDomains": ["github.com", "*.github.com", "registry.npmjs.org"]
    },
    "credentials": {
      "files": [
        { "path": "~/.ssh", "mode": "deny" },
        { "path": "~/.aws/credentials", "mode": "deny" }
      ],
      "envVars": [
        { "name": "GH_TOKEN", "mode": "mask", "injectHosts": ["api.github.com"] },
        { "name": "NPM_TOKEN", "mode": "deny" }
      ]
    }
  },
  "permissions": {
    "deny": ["Read(~/.ssh/**)", "Read(~/.aws/**)", "Read(**/.env)", "Read(**/.env.*)"]
  }
}

A few details that are easy to get wrong:

  • Mask needs TLS termination. tlsTerminate: {} is marked experimental and makes the proxy generate a certificate authority for the session. Without it, the placeholder reaches GitHub unchanged and authentication fails. Nothing leaks, but nothing works either. claude doctor warns about this.
  • Mask only works from trusted scopes. Claude Code ignores mask entries and tlsTerminate in a repository’s .claude/settings.json, so a cloned repo can’t redirect your real token. Put them in user or managed settings.
  • The sandbox block covers sandboxed Bash only. The Read tool follows permission rules, which is why the permissions.deny rules are there. Hooks and stdio MCP servers still inherit your environment. Setting CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 strips most credentials from every subprocess Claude Code starts, though the env var docs say it leaves GitHub tokens in place.
  • allowUnsandboxedCommands: false stops the agent from retrying a blocked command outside the sandbox.
  • Every allowed domain is also a way out. github.com is in the list so git works, and it’s also a place the agent can push data to. Keep the list short, and remember that a host where the proxy injects a credential is one where the agent can act as you.

op run from 1Password is useful for humans, but it doesn’t protect you from the agent. It puts the real secret in the environment of the process it starts. If that process is the agent’s shell, the agent can read it.

There’s also a pattern for when the credential has to stay on your laptop. A small tool called lend, described in a November 13 post, lets a remote agent ask your laptop to run a specific command, such as gh, after a Touch ID approval, so “the token never leaves the laptop.” The author names the limit himself: “If I approve a shell, an interpreter, or anything that reads instructions from stdin, I’ve basically approved running anything on my laptop.” The HN thread on it is a good list of other setups, from separate agent GitHub accounts to keeping secrets on a second laptop behind a small API.

How narrow should the agent’s token be?

As narrow as the task, and short-lived. Scope limits what a stolen token can do, and expiry limits how long it’s useful.

  • GitHub: a GitHub App installation token “will expire after 1 hour” and can be limited to specific repositories and permissions when you mint it. A fine-grained personal access token is the fallback: specific repositories, specific permissions, and an expiry you choose. GitHub allows non-expiring tokens unless an org policy blocks them, so set a short date yourself. Classic tokens are too broad for this.
  • AWS: since November 19, STS GetScopedCredentials narrows your existing temporary credentials for an agent or sub-agent without creating a new role. Permissions and session duration “never exceed those of the caller.”
  • Everything else: a separate identity for the agent, so its actions don’t look like yours in the audit log.

The strongest version is to make sure the agent never holds a write credential at all. That’s how I built Smi. The job that runs the model has a read-only GitHub token. A separate job that the model can’t reach applies its patch and opens a draft PR. On real runs, the agent’s token got 403 Write access to repository not granted when it tried to push. GitHub’s refusal is what enforced the rule, so nothing depended on the model following instructions.

Setup work is an easy place for a token to slip into a session, for example when you ask an agent to wire up deploy secrets. Set the value yourself instead. Run gh secret set DEPLOY_TOKEN in your own terminal and it prompts for the value, so the token goes to GitHub without entering the agent’s transcript. If a token did pass through a session, rotate it once setup is done. Transcripts are kept on disk, and as the Cursor case shows, copies held by a vendor can leak too. Treat anything an agent has seen as copied.

What are “shadow agents”, and should a small team care?

They’re coding agents running on company machines that nobody approved or inventoried. Big vendors now treat them as a governance problem. A small team can copy the main ideas without buying anything.

At Ignite on November 17, Microsoft announced that Defender and Entra now discover more than 60 local AI agents, including Claude Code and GitHub Copilot CLI, and the MCP servers they use. Entra Agent ID assigns those agents their own identity, and Entra Global Secure Access adds network controls for agents and MCP servers, including an MCP Firewall. Intune can mark devices with unapproved agents as noncompliant. All three are in preview. Local discovery in Defender, and Defender’s runtime protection for Claude Code and Copilot CLI on Windows, are generally available.

A 20-person startup can get most of the value without any of that stack. Keep a list of which agents and MCP servers run on which machines. Give each agent its own identity so its actions show up as the agent’s in audit logs, not yours. And keep an allowlist of MCP servers and plugin sources; before you install an AI skill covers how to vet what goes on it.

What I’d do this week

  1. Turn on your agent’s sandbox, and set allowUnsandboxedCommands to false or your tool’s equivalent.
  2. Deny ~/.ssh, ~/.aws and .env files to both the sandbox and the file tools.
  3. Remove long-lived tokens from the shell profile your agent inherits. Replace them with masked placeholders or short-lived tokens minted per task.
  4. Swap classic GitHub tokens for fine-grained ones or a GitHub App, scoped to the repos the agent works on.
  5. Move unattended or permission-skipping runs into a dev container or microVM with an egress allowlist and no mounted host credentials.
  6. Split any agent pipeline that pushes, deploys or publishes into an agent step and a separate step that holds the write credential. If that pipeline runs in CI, what can your CI reach? is the audit for the secrets it holds.
  7. Rotate any credential you’ve pasted into an agent chat, and set new secrets from your own terminal.

Where your prompts and the secrets in them go after they leave your machine is a separate question, covered in who reads your prompts. If you’d like a second pair of eyes on how your team’s agents are set up, that’s the kind of review I do as a fractional CTO.

Further reading

Questions

Can Claude Code read my SSH keys and AWS credentials?

By default, yes. Claude Code's sandbox is off by default, and even when it's on, sandboxed commands can read most of the machine, including ~/.ssh and ~/.aws/credentials, and they inherit secrets from the environment. You have to list credential files and variables under sandbox.credentials to deny or mask them, and add Read deny rules for the file tools.

What is the safest way to give a coding agent a GitHub token?

Don't put a token in its environment at all. Run the agent in a sandbox whose proxy injects the real token only on requests to api.github.com, and keep the agent's copy a placeholder. If it must hold a token, use a GitHub App installation token, which expires after an hour and can be limited to specific repositories and permissions, or a fine-grained personal access token.

Is a Docker container enough to sandbox an AI coding agent?

For a trusted agent on your own code, a container or the agent's built-in sandbox is a big improvement over nothing. It shares the host kernel, so for untrusted repositories, unattended runs or skipped permission prompts, prefer a microVM such as Docker Sandboxes or Microsandbox, or a throwaway VM. Whatever you use, don't mount ~/.ssh or cloud credential files into it.

Does telling the agent not to touch secrets work?

No. The instruction is just more input to the model, and the agent also reads issues, READMEs, web pages and tool output that anyone can write. Prompt injection can override it. Controls that hold are the ones the model can't change, such as file permissions, network allowlists and token scopes.

About the author

Software engineer and serial founder in Alexandria, Egypt, and CTO at Zaher.AI, a GEO and SEO agency serving MENA.

Console

Type help and press Enter.