Skip to main content
AWS Nitro Sandboxes run each Kubernetes pod in its own lightweight virtual machine, with its own Linux kernel. This protects your nodes and other pods from the agent: if the agent runs code that escapes its container, it only reaches the virtual machine’s kernel, so it can’t read other pods’ data and secrets (or use the node’s AWS credentials). However, running an agent in a Nitro Sandbox doesn’t protect the API keys in the agent’s own pod. An agent runs commands that a prompt can influence, so any key in the agent’s pod can leak through a prompt injection. With Agent Vault, agent pods contain no API keys. Each pod receives a session token instead, and sends its requests through an Agent Vault proxy that attaches the real credentials.

How it works

This guide sets up an EKS Auto Mode cluster where each agent runs in its own Nitro Sandbox and can only connect to the proxy: Your orchestrator is a program that starts each agent run, such as a script or a CI job. For each agent run, it does the following:
  1. Creates a session for the run
  2. Starts the agent’s pod with the session token
  3. Revokes the session and deletes the pod when the agent finishes
The proxy runs without a sandbox, because it runs no code that a prompt can influence.

Prerequisites

  • The Admin role in an Agent Vault project
  • An access bundle with a service for each key the agent uses, including its model provider’s key, such as Anthropic for Claude Code (see the quickstart)
  • An AWS account on a paid plan where you can create EKS clusters (on the free plan, AWS only launches instance types that can’t run Nitro Sandboxes)
  • The AWS CLI, eksctl, kubectl, and jq
  • curl and openssl on the machine where you run the script in Step 7, if you use the Bash version

Step 1: Create the cluster

Create an EKS Auto Mode cluster

Nitro Sandboxes need EKS Auto Mode and Kubernetes 1.36 or later. Create a cluster with eksctl, replacing <cluster-name> and <region>:
Pass --version, because eksctl creates an older Kubernetes version by default. To use a cluster you already have, check that it runs Auto Mode and Kubernetes 1.36 or later.

Turn on network policies

EKS accepts network policies without enforcing them until you turn on its network policy controller. Save this manifest as enable-network-policy.yaml and apply it to your cluster:

Create a node pool for agents

A node loads a new pod’s network policies a moment after the pod starts. Auto Mode’s nodes allow all traffic until then, so an agent’s first requests can skip the proxy. To close that gap, run agent pods on their own nodes, which deny all traffic until the policies load. Create a NodeClass named agents that copies the cluster’s default NodeClass and sets networkPolicy to DefaultDeny:
Save this manifest as agents-nodepool.yaml and apply it to your cluster. It launches nodes for agent pods from the agents NodeClass:
The taint keeps every other pod off these nodes, because a pod that no network policy selects gets no traffic on them. The agent pod in Step 7 tolerates it.

Find the cluster’s DNS address

Auto Mode runs a DNS server on each node at a fixed address. The network policies in Steps 3 and 4 allow DNS lookups only to that address. To find it, get the cluster’s service address range:
The DNS address is the .10 address in that range. For example, if the range is 10.100.0.0/16, the DNS address is 10.100.0.10. Later steps call this address <dns-ip>.

Step 2: Set up Agent Vault

Create a proxy

1
In the Agent Vault project that holds your access bundle, go to Proxies and select Create Proxy. An agent can only use a proxy in the same project as its session.
2
Enter a Name, such as sandboxes.
3
Select Create, then copy the proxy token from the Proxy Token dialog. Infisical shows the token only once.

Create a machine identity for your code

Your code creates a session for each run as a machine identity. Give the machine identity the Member role and access to only your access bundle.
1
In your Agent Vault project, go to Access Control > Machine Identities and select Add Machine Identity.
2
On the Create New tab, enter a Name, choose Member in Role, then select Create. Infisical creates the machine identity with Universal Auth and opens its page.
The Add Machine Identity to Project panel on the Create New tab, with ci-runner as the name and Member as the role
To use a machine identity that already exists in your organization, select the Assign Existing tab instead.
3
On the machine identity’s page, select Universal Auth under Authentication. Copy the Client ID, then select Add Client Secret and copy the client secret.
4
Go to Access Bundles and open the access bundle the agent uses. Select Options > Manage Access. Under No Access, select Grant Access next to the machine identity.

Step 3: Deploy the proxy

Save this manifest as agent-vault-proxy.yaml, replace <dns-ip> with the address from Step 1, and apply it to your cluster. It creates the agent-vault namespace and runs the proxy in it:
  • Instance URL: if you use EU Cloud or self-host Infisical, replace https://app.infisical.com with https://eu.infisical.com or the URL of your self-hosted instance
  • Egress: the proxy can only reach public addresses on ports 443 and 80, so add an egress rule for anything else, such as a self-hosted Infisical instance in your VPC or a service at api.example.com:8443

Store the proxy token

Store the proxy token in a Secret named agent-vault-proxy in the agent-vault namespace, replacing <proxy-token>:
The proxy’s pods start once the Secret exists. On the Proxies page of your Agent Vault project, the proxy’s status changes to Healthy once it connects. Both replicas use the same token and certificate authority, and the Service spreads connections across them (high availability).

Step 4: Create the agents namespace

Save this manifest as agents-namespace.yaml, replace <dns-ip>, and apply it to your cluster. It creates the agents namespace and blocks all traffic to and from its pods, except DNS lookups and connections to the proxy:
EKS enforces these network policies on the node, so code in the agent’s pod can’t turn them off.
The restricted label on the namespace turns on Kubernetes’ strictest Pod Security Standard, so Kubernetes rejects any pod in the namespace that runs as root, keeps Linux capabilities, or allows privilege escalation. The agent pod in Step 7 passes these checks. If you change its securityContext, keep those settings, or Kubernetes won’t create the pod.

Step 5: Set up your orchestrator

Your orchestrator starts each agent run. It can be a script, a CI pipeline, a job runner, or a Kubernetes controller. Run it outside the agents namespace, so agent pods can’t reach it.

Give your orchestrator the machine identity’s credentials

Set the client ID and client secret of the machine identity from Step 2 in the environment where your orchestrator runs:
If your orchestrator runs on AWS, such as in this cluster or in AWS Lambda, use AWS Auth instead. This lets your orchestrator log in with its IAM role, so it doesn’t need to store any credentials from Infisical.

Allow the orchestrator to start agent pods

Save this manifest as agent-orchestrator-role.yaml and apply it to your cluster, then bind the role to the service account or user that your orchestrator runs as. The role only applies in the agents namespace:

Step 6: Build the agent’s image

Build an image from this Dockerfile and push it to a registry your cluster can pull from, such as Amazon ECR:
  • The node user: the restricted Pod Security Standard refuses pods that run as root, and Claude Code won’t skip its permission prompts as root, so the agent runs as the image’s node user
  • The entrypoint: infisical agent-vault run fetches the proxy’s certificate, sets the proxy and certificate trust variables, and starts the agent’s command after --
  • curl: the checks in Step 8 run it in the agent’s pod

Step 7: Run an agent

Define the agent’s pod

Save this manifest as agent-pod.yaml. The script in the next step starts a pod from it for each run. The runtimeClassName field runs the pod in its own Nitro Sandbox:
Remove the real API keys from your agent’s configuration. If your agent or a tool it runs won’t start without a key, pass a placeholder such as agent-vault, as this pod does for Claude Code’s ANTHROPIC_API_KEY.

Start the agent with a new session

Each of these scripts is a minimal orchestrator that runs one agent with its own session. Run it in the folder with agent-pod.yaml. Replace <project-id> with the ID of your Agent Vault project (find the project ID), <access-bundle-name> with your access bundle’s name, and https://app.infisical.com with your instance’s URL if you don’t use US Cloud:
Save this script as run-agent.sh and run it with bash run-agent.sh:
If your orchestrator is written in another language, have it do what these scripts do:
  1. Log in with the Universal Auth Login endpoint
  2. Create a session with the Create session endpoint
  3. Store the session token in a Secret, and start the agent’s pod from agent-pod.yaml
  4. When the agent exits, or if the script fails or is canceled, revoke the session with the Revoke session endpoint
  5. Delete the pod and its Secret

Step 8: Verify it works

A short task can finish before you can check its pod, so start a test run whose pod waits for 10 minutes instead of running the agent:
  1. In agent-pod.yaml, replace the args list with ["sleep", "600"]. The image’s entrypoint still starts the command with infisical agent-vault run, so the pod gets its session the same way an agent does.
  2. Run your script from Step 7.
While the pod waits, run these checks as a cluster admin in another terminal. Replace <run-id> with the run ID the script printed, and <api-host> with a host in your access bundle:
To check that the pod runs in a Nitro Sandbox, count the CPUs the pod sees. A sandbox is a virtual machine with only the pod’s CPU limit, so this prints 2. A pod without a sandbox sees every CPU on its node:
In your Agent Vault project, find the session under Sessions > All Sessions by its label, eks run <run-id>. It’s Active while the pod runs. View the session’s logs to see the requests from your checks. When you’re done, press Ctrl+C in the script’s terminal. The script revokes the session and deletes the pod, and the session changes to Revoked. Then put the agent’s args back in agent-pod.yaml.
Your agents now run in Nitro Sandboxes that contain only a session token, can only connect to the proxy, and lose access when the session is revoked.

Security considerations

  • Hosts through the proxy: agent pods can only connect to the proxy and DNS, but under the default traffic policy, Any host, the proxy forwards their requests to any host its network policy allows (to allow only the hosts that services in the session’s access bundle cover, set the traffic policy to Service hosts only and add any other hosts the agents need to the proxy’s exceptions)
  • DNS: agent pods still need DNS to find the proxy, and DNS lookups can carry data out of the pod, so a network policy doesn’t close every channel
  • The node: in isolated mode, the node can read the agent pod’s files and its traffic to the proxy, so limit who can access your nodes
  • APIs that echo requests: if an endpoint returns the request’s headers in its response, such as an echo or debug endpoint, the response exposes the credential that the proxy attached, so limit each service to the methods and paths the agent needs
  • Revoking a session: the proxy stops attaching credentials for a revoked session within one poll interval
  • Several teams: a proxy’s traffic policy and exceptions apply to every agent that uses it, so give each team or customer its own proxy and agents namespace if they need different access
  • Unsupported connections: WebSocket connections and clients that only speak HTTP/2, such as gRPC clients, fail through the proxy (see Supported connections)

FAQ

A confidential sandbox only starts a pod that matches a policy you generate from the pod spec in advance. That policy includes the container’s arguments. The agent’s prompt is an argument and changes on every run, so you’d need a new policy for every run. A confidential sandbox also refuses kubectl exec, which the checks in Step 8 use.Confidential mode protects a pod’s data from the node that runs it. If you need that protection, see Run a pod in confidential mode.
Yes, but you prepare the nodes yourself. The nodes need:Outside Auto Mode, DNS runs in pods labeled k8s-app: kube-dns in kube-system. Allow DNS to those pods in both network policies instead of to <dns-ip>.Node groups don’t use the agents NodeClass and NodePool, so remove nodeSelector and tolerations from the agent pod. The RuntimeClass already schedules the pod only on nodes that can run Nitro Sandboxes. To block agent pods’ traffic until their policies load, set the VPC CNI’s network policy mode to strict. Strict mode applies to every pod in the cluster, so every pod then needs a network policy, including CoreDNS.
A network policy applies to a whole pod, and every container in a pod shares the pod’s Nitro Sandbox. A proxy in the agent’s pod would need a route to the internet that the agent could also use, and its proxy token would sit beside the agent.

Troubleshooting

Auto Mode can’t launch a node for a Nitro Sandbox in these cases:
  • The agents NodeClass or NodePool from Step 1 doesn’t exist
  • The cluster runs a Kubernetes version older than 1.36
  • The NodePool’s NodeClass uses FIPS AMIs
  • The NodePool only allows GPU or Neuron instance types
The network policy controller is off, so EKS accepts the network policies but nothing enforces them. Apply the ConfigMap in Turn on network policies.
The network policies allow DNS only to <dns-ip>. Check that <dns-ip> is the .10 address of your cluster’s service address range (find the cluster’s DNS address). Until DNS works, the proxy never becomes ready, and infisical agent-vault run can’t find the proxy.
The proxy’s network policy blocks the host or port. It allows only ports 443 and 80 on public addresses, so add an egress rule to the policy in Step 3 for a private address or another port.
The agent’s HTTP client doesn’t trust the proxy’s certificate. Check that the agent starts through infisical agent-vault run, as the image’s entrypoint does, and that its HTTP client reads one of the certificate trust variables.
The proxy’s traffic policy blocks hosts that no service in the access bundle covers. Add a service for the host, or add the host to the proxy’s exceptions.

Next steps

Session logs

Record every request an agent makes during a session.

Proxies

Change the proxy’s traffic policy, exceptions, and poll interval.