Secure AWS Credentials for Claude Code Agents

Diagram idea for secure AWS credentials in a coding agent sandbox

Sign in with aws sso login, launch a coding agent, and that agent can use every AWS role your session is allowed to assume. A new open-source setup aims to secure AWS credentials for tools like Claude Code: the real session stays on the host and the agent receives only short-lived keys.

The author’s worry is easy to state. Plenty of developers can assume an AdministratorAccess role, and an agent able to read ~/.aws inherits that power.

Why built-in limits do not secure AWS credentials

Agents should get the same least-privilege treatment as people, with IAM roles made just for them. The agent also has to be kept out of ~/.aws, the folder where AWS tooling caches credentials and SSO sessions. SSH keys and GitHub tokens typically live on the same laptop too.

Three approaches that fell short

The first try was manual: wipe all AWS credentials from the machine and paste temporary ones into each terminal. That worked but got old fast.

Next was the AWS MCP Server, a managed remote server that AWS runs. Under OAuth the agent holds just a short-lived token. SigV4 with the MCP Proxy for AWS adds profile switching across accounts. IAM condition keys can separate agent requests from your own, and CloudTrail logs everything. It still had two drawbacks:

  • The agent is limited to the server’s tools, which are documentation search and a sandboxed Python runtime for AWS API calls. The AWS CLI and SDKs are off the table in its own environment.
  • SigV4 needs the proxy beside the agent, reading ~/.aws, so an agent with file access could grab the SSO session itself. OAuth sidesteps that, yet ties each session to one IAM role and so rules out cross-account work.

AWS Lambda MicroVMs came next, as short-lived self-hosted Claude Code environments with an IAM role attached. The catch was working through Claude’s web interface instead of a terminal, plus approving Claude’s GitHub app, which gets broad access to each repository you allow.

The Docker Sandboxes approach

Docker Sandboxes puts agents like Claude Code, Codex or Copilot CLI in their own microVM with a separate Linux kernel. Inside it, an agent can install packages, start containers and run unattended while the host’s files, network and Docker daemon stay out of reach.

By default, secrets stay on the host and a proxy overwrites the auth header of outbound requests. AWS breaks that model, since it has no static key header. Each request is signed with Signature Version 4, and the signature depends on the request contents, so a proxy can’t add it afterward. The agent must sign requests, which means it needs credentials.

How the broker works

The project, sbx-aws-developer, comes in two pieces. The kit, widdix/sbx-kit-aws-developer, sits on top of an agent image such as claude and supplies AWS tools and configuration. The broker, widdix/sbx-aws-developer, is a container on the host’s Docker that gives one sandbox temporary credentials for selected AWS profiles.

Once a minute the broker calls aws configure export-credentials per profile and swaps in new credentials ahead of expiry. Its output lands in a folder that the sandbox mounts read-only at /mnt/aws-credentials. A JSON file lists the access key, secret, session token, expiration and account ID for each profile. An AWS config file defines one profile per entry, each using credential_process to pull fresh credentials when needed. The AWS CLI and SDKs then behave normally in the sandbox, and AWS_PROFILE selects the profile.

The agent never sees ~/.aws or the SSO session. To secure AWS credentials this way, treat the profile list as your permission boundary: build least-privilege permission sets for agents and never hand over an AdministratorAccess profile.

Credentials live for the permission set’s session length, which is one hour by default and can reach twelve. After the SSO session lapses, errors in the sandbox ask for a new aws sso login on the host, and the broker notices the fresh session within a minute. Profiles with long-term access keys are rejected.

Limits to know about

  • Stopping the broker doesn’t revoke credentials an agent already copied. They stay valid until they expire, so short session durations help.
  • The kit allows egress to amazonaws.com and other AWS domains, so issued credentials work against any account and region they are valid for.
  • The broker mounts ~/.aws read-write because the AWS CLI writes the SSO token cache. The sandbox never sees that directory.
  • The commands target macOS and Linux shells, and sbx env is experimental.
  • Kits and mounts apply only when a sandbox is created, so changes mean removing and restarting it.

Setting it up

You need sbx 0.45 or later and Docker. The author tested with sbx 0.54. Both images come from Docker Hub, and the AWS CLI is needed on the host only for aws sso login.

Give each project its own directory with an sbxenv.yaml file next to a src folder holding the project’s repositories. Only src is mounted as the workspace, so the agent can’t read or change the environment file. You sign in once with aws sso login --sso-session, list the allowed profiles in the YAML, and start the sandbox.

The kit is pinned to version 1.0.0, and the broker image tracks the major tag :1. To update, pull widdix/sbx-aws-developer:1 and start the sandbox again. When you remove a sandbox, its broker container is stopped and removed too.

Source: cloudonaut

Written by

Saksham Bhargava

Saksham Bhargava runs Alteroid and has been writing about consumer technology for over five years, covering iPhone, Android, Windows, AI tools and gaming. With an MCA and six years of hands-on web development experience, he tests the features he writes about on his own devices and focuses on clear, practical guides that solve real problems. Away from the screen, he enjoys travelling to places most tourists skip.