Sandbox and secret hygiene for coding agents
Coding agents with shell and network tools are powerful. Without sandboxing and secret hygiene, they are also a breach workflow.
Coding agents with shell and network tools are powerful. Without sandboxing and secret hygiene, they are also a breach workflow. The trap is soft trust: “it is just our repo.” Agents follow instructions from files and tool outputs, so a hostile README, issue, or pasted log can become an exfiltration path.
Treat agent runtime like a CI runner: least privilege, allowlists, and no ambient production credentials.
What the agent may touch (and what it must not)

Sandbox
Allow by default:
- Writes inside a path allowlist for the task.
- Read access to the docs and source needed for the job.
- Scoped test and lint commands.
- Ephemeral tokens scoped to the task.
Deny by default:
- Prod kube contexts and cloud admin roles.
- Secret store write access from agent sessions.
- Unrestricted
curl/ network egress. - Destructive operations without a human approval step (
rm -rf, drop database,terraform apply, force push).
Separate identities: laptop agent, CI agent, and production systems never share the same long-lived keys.
Workflow: inventory → deny → allowlist → human gate
- Inventory capabilities. Filesystem write roots, network egress, cloud CLIs, container sockets, MCP tools.
- Deny prod and admin. Remove ambient credentials from shells used for agent work.
- Allowlist paths and commands. Prefer ephemeral tokens. Scope each MCP tool as a privilege grant; disable unused servers.
- Secret scan and redact. Keep secrets out of prompts and repos. Redact tool outputs before they re-enter the prompt loop when they may contain tokens.
- Human-gate destructive ops. Require approval for anything irreversible.
- Run a short drill. Can the agent reach prod? Can a malicious README exfiltrate an env file? Fix gaps the same day.
Stop gates
- Cloud admin credentials in the same shell the agent controls.
- Unrestricted network tools enabled “for convenience”.
- API keys in a committed
.env“temporarily”. - Trusting model judgment as the security boundary.
Checklist before you enable shell tools
- Agent capabilities inventoried and minimized.
- Prod credentials absent from agent environments.
- Destructive command approvals required.
- Secret scanning on for PRs.
- Injection / exfil drill completed in the last quarter.
Three failures that justify pausing agents

Failure modes to catch early
- Shared admin keys. Cloud admin creds live where the agent can use them. Fix: dedicated OS user or container profile; remove admin roles from agent shells.
- Open egress. Unrestricted network lets hostile text exfiltrate secrets. Fix: deny-by-default egress; allowlist destinations.
- Model as boundary. “Be careful” prompts instead of controls. Fix: inventory, minimize, allowlist. Log tool invocations for background agents.
Assume chat storage is a future breach artifact. Rotate any token that ever appeared in an agent transcript.
Bottom line

When this fits vs when it does not
Sandboxing is how you keep coding agents useful without turning them into a breach workflow. Least privilege, human-gated destruction, and secret hygiene beat soft trust. Pair this with agent onboarding checklists so new sessions prove the safe path first, and with PR description quality so secrets never land in the merge record.
Share