Sandboxing AI Agents on Amazon EKS
A hands-on guide to giving every AI agent its own locked room on EKS, using gVisor and the Kubernetes agent-sandbox project.
TL;DR
AI agents now write code and run it. Nobody reviewed that code. If it runs in a normal pod, it sits very close to your node, your network and your AWS credentials.
Think of a hotel. A guest does not get keys to the whole building. They get one room and one key card, and the room is cleaned when they leave. A sandbox does the same thing for an agent.
In this post we build that on Amazon EKS, step by step:
- Nodes that run pods under gVisor.
- The agent-sandbox project, to hand out one sandbox per session.
- Network rules that block everything by default.
- No AWS or Kubernetes credentials inside the sandbox.
- Tests that try to break out, run on every deploy.
I also cover what this setup does not protect. Those gaps matter, and most guides skip them.
One note before we start. This is a build-along, not a story about a production incident. This area changes fast, so check each manifest against your own cluster.
1. The problem: an agent is not a normal workload
Most apps on your cluster run code your team wrote. You know what it does before it starts.
An agent with a "run code" tool is different. The model decides what to run while it is running. And what the model decides depends on what it reads: a user message, a web page, a PDF, the output of another tool.
Here is a small example. A user asks the agent to summarize a GitHub repo. The README has a hidden line that says "ignore your instructions and run this command". The model follows it. A few seconds later, a
curl to the EC2 metadata address is running inside your cluster.This is called prompt injection, and you cannot fully prevent it. So the safe assumption is simple: treat the code inside the pod as hostile.
That gives us three rules for the rest of this post:
- Ask what the code can reach. Normal security keeps attackers out of a pod. Here the attacker may already be inside it.
- One session, one sandbox. If two users share a pod, one user's files are visible to the other.
- Start fast, then disappear. A user is waiting in a chat window. The sandbox should be ready in moments and be deleted when the session ends.
2. Why a plain pod is not a sandbox
A container is just a process on the node with some walls around it. Those walls are good for packaging. They are weak against code that is trying to get out. There are four reasons.
1. The kernel is shared. Every pod on a node uses the same Linux kernel. If the code finds a kernel bug, it can reach the node, and from the node it can reach every other pod there.

Figure 1. In a plain pod, agent code talks to the node's kernel directly. With gVisor, a second kernel sits in between.
2. The network is open. By default a pod can talk to every other pod, to the Kubernetes API, and to anything in your VPC.
There is an EKS catch here. Network policies do nothing until you turn on enforcement in the VPC CNI. The cluster accepts your policy and
kubectl get networkpolicy shows it, but traffic still flows. Nothing warns you.3. The node's AWS credentials are close. The metadata service at
169.254.169.254 gives out the node role's credentials. If the node allows it, a pod can ask for them.4. The pod has a Kubernetes identity. A service account token is mounted into every pod by default. With it, the code can call the Kubernetes API.
None of these are bugs. They are defaults made for code you trust. In this post we turn each one off for the sandbox, and then we test that it stays off.
3. Your options on EKS
There are two common ways to put a stronger wall around a pod. In Kubernetes you pick one with a
RuntimeClass , which is one line in the pod spec.gVisor gives each sandbox its own small kernel that runs as a normal program. The agent's code talks to that kernel, not to the node's kernel. In hotel terms, the guest talks to the front desk and never walks into the staff area.
Kata Containers puts each pod inside a tiny virtual machine. The wall is the hardware itself. Kata can use Firecracker, the same technology behind Lambda and Fargate.
| gVisor | Kata Containers |
|---|---|---|
How it isolates | A separate kernel in user space | A small VM per pod |
EC2 instances it needs | Any normal instance | Bare metal, or an instance type with nested virtualization |
Compatibility | Most Linux software works, not all | Everything works, it is a real kernel |
Main cost | Slower for heavy disk and network work | More memory per pod, slower start |
Good for | Short code-running tasks, many per node | Fully untrusted tenants, software gVisor cannot run |
The instance row is what decides it for most teams. A normal EC2 instance is already a virtual machine, and most instance types cannot run another VM inside. So Kata needs
.metal instances or one of the newer types with nested virtualization. Check the EC2 docs for the current list.gVisor has no such need. It runs on the instances you already use, and it scales with Karpenter like any other node pool. That is why this post uses gVisor. Section 9 covers when it is not enough.
Two things to know before you start:
- Use Amazon Linux 2023 for these nodes. Bottlerocket does not include gVisor.
- Fargate does not fit here. It isolates well, but pods start too slowly for a chat and you cannot pick a runtime.
4. How agent-sandbox works
gVisor builds the wall. It does not create the room, hand out the key, or clean up afterwards. For that we use agent-sandbox , a project from Kubernetes SIG Apps.
It adds four resource types. Sticking with the hotel:
Kind | Hotel version | What it does |
|---|---|---|
SandboxTemplate | The room design | The pod spec: image, runtime, security settings, limits. The platform team owns it. |
SandboxWarmPool | Rooms kept ready | Keeps a few sandboxes already running, so nobody waits. |
SandboxClaim | A booking | A request for one sandbox from the pool. Your app creates this. |
Sandbox | The room | One pod with a stable name and an end time. |
The names and fields here are from release v1.0.2. Check the API reference for the version you install.
A request goes like this:
- Your agent backend creates a
SandboxClaim.
- The controller sees the claim.
- It takes a ready sandbox from the warm pool and gives it to the claim. The pool starts a new one to replace it.
- Your backend sends commands to the sandbox through the router and reads the output.

Figure 2. The backend only creates a claim and talks to the router. It never creates a pod.
When the session ends, the sandbox is deleted.
Why this split is good for security. The app can only create claims, and a claim has no field for "make me a privileged pod" or "skip gVisor". Those choices live in the template, which only the platform team can edit. The guest can book a room. The guest cannot redesign it.
5. Step 1: nodes that run gVisor
Sandboxes get their own nodes. gVisor has to be installed on the node, and if something ever escapes a sandbox, it should land on a node that holds only other sandboxes.
We need three things: a node class, a node pool, and a runtime class. I use Karpenter, following Running gVisor on EKS with Karpenter .
5.1 The node class
This does two jobs. The shell script downloads gVisor when the node boots. The
NodeConfig part tells containerd that a runtime called runsc exists.apiVersion: karpenter.k8s.aws/v1kind: EC2NodeClassmetadata: name: sandbox-gvisorspec: role: "KarpenterNodeRole-${CLUSTER_NAME}" amiSelectorTerms: - alias: al2023@latest subnetSelectorTerms: - tags: karpenter.sh/discovery: "${CLUSTER_NAME}" securityGroupSelectorTerms: - tags: karpenter.sh/discovery: "${CLUSTER_NAME}"
# Stops pods from reading the node's AWS credentials metadataOptions: httpTokens: required httpPutResponseHopLimit: 1
userData: | MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="//"
--// Content-Type: application/node.eks.aws
apiVersion: node.eks.aws/v1alpha1 kind: NodeConfig spec: containerd: config: | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runsc] runtime_type = "io.containerd.runsc.v1"
--// Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash set -euxo pipefail URL="https://storage.googleapis.com/gvisor/releases/release/latest/$(uname -m)" cd /tmp for f in runsc containerd-shim-runsc-v1; do curl -fsSLO "${URL}/${f}" curl -fsSLO "${URL}/${f}.sha512" sha512sum -c "${f}.sha512" install -m 0755 "${f}" /usr/local/bin/ done --//--5.2 The node pool
The taint keeps normal pods off these nodes. The CPU limit caps how much the whole sandbox fleet can cost.
apiVersion: karpenter.sh/v1kind: NodePoolmetadata: name: sandbox-gvisorspec: template: metadata: labels: sandbox: gvisor spec: nodeClassRef: group: karpenter.k8s.aws kind: EC2NodeClass name: sandbox-gvisor taints: - key: sandbox value: gvisor effect: NoSchedule requirements: - key: kubernetes.io/arch operator: In values: ["amd64"] - key: karpenter.sh/capacity-type operator: In values: ["on-demand"] limits: cpu: "64"5.3 The runtime class
This is the name pods will ask for. It also sends those pods to the gVisor nodes on its own, so nobody has to remember the node selector.
apiVersion: node.k8s.io/v1kind: RuntimeClassmetadata: name: gvisorhandler: runscscheduling: nodeSelector: sandbox: gvisor tolerations: - key: sandbox operator: Equal value: gvisor effect: NoSchedule5.4 Check it
Run a test pod and read its kernel log. Under gVisor you see gVisor's own boot messages, not the node's.
kubectl run gvisor-check --image=busybox --restart=Never \ --overrides='{"spec":{"runtimeClassName":"gvisor"}}' -- dmesg
kubectl logs gvisor-check # look for "Starting gVisor"kubectl delete pod gvisor-checkThings that go wrong here
- Pod stuck with "no runtime for runsc is configured". The containerd config did not apply. The line above is for containerd 1.x. On containerd 2.x the section is
plugins."io.containerd.cri.v1.runtime".containerd.runtimes.runsc. Runcontainerd --versionon a node to see which one you have.
- Same error, config looks right. Check the user data markers. The last one must be exactly
--//--.
- Node cannot download gVisor. The node needs internet access at boot. If your subnets have none, build an AMI with the two files already in it.
- Use a fixed gVisor version in production. Replace
latestin the URL with a dated release once you have tested it.
6. Step 2: install agent-sandbox and design the room
6.1 Install the controller
export VERSION="v1.0.2" # check the releases page for the latest
kubectl apply -f \ "https://github.com/kubernetes-sigs/agent-sandbox/releases/download/${VERSION}/sandbox-with-extensions.yaml"6.2 A namespace and an empty identity
Sandboxes live in their own namespace. The service account has no permissions and no token.
apiVersion: v1kind: Namespacemetadata: name: agent-sandboxes labels: pod-security.kubernetes.io/enforce: restricted---apiVersion: v1kind: ServiceAccountmetadata: name: sandbox-no-access namespace: agent-sandboxesautomountServiceAccountToken: false6.3 The template
This is the room design. It looks long, but it is a normal pod spec inside a wrapper. I have marked the lines that matter.
apiVersion: extensions.agents.x-k8s.io/v1beta1kind: SandboxTemplatemetadata: name: python-sandbox namespace: agent-sandboxesspec: networkPolicyManagement: Unmanaged # we write our own in step 3 podTemplate: metadata: labels: app: agent-sandbox spec: runtimeClassName: gvisor # (1) run under gVisor serviceAccountName: sandbox-no-access automountServiceAccountToken: false # (2) no Kubernetes token securityContext: runAsNonRoot: true # (3) not root runAsUser: 1000 seccompProfile: type: RuntimeDefault containers: - name: runtime image: <your-ecr-repo>/python-runtime-sandbox@sha256:<digest> ports: - containerPort: 8888 securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true # (4) cannot change the image capabilities: drop: ["ALL"] resources: # (5) cannot eat the node requests: cpu: 250m memory: 512Mi limits: cpu: "1" memory: 1Gi ephemeral-storage: 1Gi volumeMounts: - name: workspace mountPath: /workspace volumes: - name: workspace # (6) the only writable place emptyDir: sizeLimit: 512MiWhat the six marked lines do:
- Every sandbox uses gVisor. The app cannot switch it off.
- There is no token file to steal.
- The code runs as a normal user, not root.
- The code cannot change system files.
- One sandbox cannot use up the node's CPU, memory or disk.
- The code can write to
/workspaceonly, up to 512 MB.
For the image, build the Python runtime example from the agent-sandbox repo and push it to your own ECR. Pin it by digest. Every sandbox starts from this image, so you want to know exactly what is in it.
6.4 The warm pool
Keep three sandboxes ready at all times.
apiVersion: extensions.agents.x-k8s.io/v1beta1kind: SandboxWarmPoolmetadata: name: python-sandbox-warmpool namespace: agent-sandboxesspec: replicas: 3 sandboxTemplateRef: name: python-sandbox6.5 A test claim
apiVersion: extensions.agents.x-k8s.io/v1beta1kind: SandboxClaimmetadata: name: session-test namespace: agent-sandboxesspec: warmPoolRef: name: python-sandbox-warmpool lifecycle: shutdownPolicy: Deletekubectl -n agent-sandboxes get sandboxwarmpool,sandboxclaim,sandbox,podYou should see three pods from the pool. One is now bound to
session-test , and a new one is starting to take its place.One detail on the claim.
shutdownPolicy: Delete removes the pod and its disk when the session ends. The default is Retain , which keeps them. For untrusted code you want them gone.7. Step 3: lock the network and the identity
gVisor protects the node. It does not control where the sandbox can connect. A locked room with a phone line to your database is still a problem.
7.1 Turn on network policy in EKS
With the VPC CNI, network policies are ignored until you switch this on. See the EKS network policy guide for version requirements.
aws eks update-addon \ --cluster-name "$CLUSTER_NAME" \ --addon-name vpc-cni \ --configuration-values '{"enableNetworkPolicy":"true"}'7.2 Block everything
Start from zero. Nothing in, nothing out.
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: default-deny namespace: agent-sandboxesspec: podSelector: {} policyTypes: ["Ingress", "Egress"]7.3 Let the router in
The router is the only thing allowed to call the sandbox.
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: allow-router namespace: agent-sandboxesspec: podSelector: matchLabels: app: agent-sandbox policyTypes: ["Ingress"] ingress: - from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: agent-sandbox-system ports: - protocol: TCP port: 8888Check which namespace your router runs in with
kubectl get svc -A | grep sandbox-router , and change the label if it is different.7.4 Let DNS out
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: allow-dns namespace: agent-sandboxesspec: podSelector: matchLabels: app: agent-sandbox policyTypes: ["Egress"] egress: - to: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system podSelector: matchLabels: k8s-app: kube-dns ports: - protocol: UDP port: 53 - protocol: TCP port: 53With these three policies the picture looks like this:

Figure 3. The router can call the sandbox. The sandbox can look up names. Everything else is closed.
7.5 Optional: allow the public internet
Some agents need
pip install or need to fetch a URL. If you must open this, open the internet only and keep all private addresses closed.apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: allow-public-https namespace: agent-sandboxesspec: podSelector: matchLabels: app: agent-sandbox policyTypes: ["Egress"] egress: - to: - ipBlock: cidr: 0.0.0.0/0 except: - 10.0.0.0/8 # your VPC - 172.16.0.0/12 - 192.168.0.0/16 - 169.254.0.0/16 # AWS credential endpoints ports: - protocol: TCP port: 443The
except list is the important part. It keeps the sandbox away from your VPC and from the two addresses that hand out AWS credentials. Section 9 explains why this option is still risky.7.6 Identity: the sandbox gets none
Identity | How we remove it |
|---|---|
Kubernetes token | automountServiceAccountToken: false on the pod and the service account |
AWS role for the pod | No Pod Identity association and no IRSA annotation on sandbox-no-access |
Node's AWS role | Hop limit of 1 on the node, plus 169.254.0.0/16 blocked in the network policy |
What if the code needs a file from S3? The backend downloads it and passes the content in. The sandbox never holds a key.
7.7 What the backend is allowed to do
The agent backend only needs to create and delete claims.
apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata: name: sandbox-claimer namespace: agent-sandboxesrules: - apiGroups: ["extensions.agents.x-k8s.io"] resources: ["sandboxclaims"] verbs: ["create", "get", "list", "watch", "delete"]It cannot touch pods, templates or warm pools. If the backend is ever compromised, the attacker can book rooms and nothing more.
8. Step 4: call the sandbox from your agent
The project has a Python client called
k8s-agent-sandbox . It creates the claim, waits for the sandbox, and sends commands through the router. The client README has the full list of options.pip install k8s-agent-sandbox8.1 Connect
from k8s_agent_sandbox import SandboxClientfrom k8s_agent_sandbox.models import SandboxDirectConnectionConfig
ROUTER = "http://sandbox-router-svc.agent-sandbox-system.svc.cluster.local:8080"
client = SandboxClient( connection_config=SandboxDirectConnectionConfig(api_url=ROUTER))8.2 The simplest possible run
Get a sandbox, run one command, throw the sandbox away.
sandbox = client.create_sandbox( warmpool="python-sandbox-warmpool", namespace="agent-sandboxes",)try: result = sandbox.commands.run("python -c 'print(2 + 2)'") print(result.stdout) # 4finally: sandbox.terminate()8.3 A tool your agent can use
This is the same idea, shaped as a function you can register as a tool in your agent framework.
import base64
TIMEOUT_SECONDS = 30MAX_OUTPUT = 20_000
def run_python(code: str) -> str: """Run Python code written by the model. Return what it printed.""" sandbox = client.create_sandbox( warmpool="python-sandbox-warmpool", namespace="agent-sandboxes", ) try: # Send the code as base64 so quotes in it cannot break the shell. encoded = base64.b64encode(code.encode()).decode() sandbox.commands.run(f"echo {encoded} | base64 -d > /workspace/main.py")
result = sandbox.commands.run( f"timeout {TIMEOUT_SECONDS} python /workspace/main.py" ) return result.stdout[:MAX_OUTPUT] finally: sandbox.terminate()Three small choices in there are on purpose:
-
finally: sandbox.terminate(). The sandbox is deleted even if the code crashes. A forgotten sandbox costs money and keeps a user's files around.
-
timeout 30. A script with an endless loop stops after 30 seconds.
-
[:MAX_OUTPUT]. The output goes back to the model. Cut it, and never pass it to a shell or a SQL query in your backend. It came from untrusted code.
In a real agent you would keep one sandbox for the whole conversation and delete it at the end, so files from one step are there for the next.
9. What this does not protect, and what to do about it
It is tempting to stop at section 8 and say the agent is sandboxed. It is much safer than before. But there are still holes, and you should know them.
9.1 The agent's other tools
The sandbox only covers code execution. Most agents also have tools that query a database, send email, or read from S3. Those tools run in your backend with real credentials.
An injected prompt does not need to break out of gVisor. It can simply ask the agent to use the email tool.
What to do: give each tool only the access of the user who is asking. Ask for confirmation before actions that cannot be undone. Log every tool call.
9.2 DNS can leak data
We allowed DNS. Code in the sandbox can look up a name like
the-secret-data.attacker.com . The lookup itself carries the data out, and no normal connection is ever made.What to do:
- If the sandbox only does calculations, remove the DNS policy. It does not need names.
- Otherwise, use Route 53 Resolver DNS Firewall with a list of allowed domains.
9.3 Internet access can leak data too
If you applied the optional policy in 7.5, the sandbox can send anything it holds to any server on the internet.
What to do:
- For
pip install, use a private package mirror such as CodeArtifact through a VPC endpoint. Then no internet route is needed.
- For web access, send traffic through a proxy that logs and filters by hostname. Let the sandbox reach the proxy only.
9.4 gVisor is strong, not perfect
gVisor is software, and software has bugs. For most internal agents it is a good wall. If you run code from anonymous users, or you must keep paying customers apart, use Kata Containers for a hardware wall. The rest of this setup stays the same. Only the node pool and the runtime class change.
Also, some programs do not run under gVisor, and heavy disk or network work is slower. Test your real workloads before you commit.
9.5 Someone will try to mine crypto
Free CPU attracts abuse. The limits are already in our manifests. Make sure all five are really there:
- CPU, memory and disk limits on the container
- a size limit on the workspace volume
- an end time on every claim (
lifecycle.shutdownTime)
- a CPU limit on the Karpenter node pool
- a limit in your backend on sandboxes per user
9.6 One template, many sandboxes
Every session starts from the same image and the same template. One bad image, or one loosened setting, affects everyone at once.
What to do: pin the image by digest, scan it, and limit who can edit the
SandboxTemplate . Review a change to it the way you would review a change to an IAM policy.10. Prove it: tests that try to break out
Every lock in this post can be undone by a small change that looks harmless. Someone edits the node class and the hop limit goes back to 2. An add-on upgrade turns network policy off. Nothing breaks, so nobody notices.
So we write tests that act like an attacker. Each one runs a command inside a real sandbox and checks that it failed.
10.1 Setup
One sandbox is shared by all the tests.
can_connect tries to open a connection and prints OPEN or CLOSED .# tests/test_sandbox.pyimport osimport pytestfrom k8s_agent_sandbox import SandboxClientfrom k8s_agent_sandbox.models import SandboxDirectConnectionConfig
client = SandboxClient( connection_config=SandboxDirectConnectionConfig( api_url=os.environ["SANDBOX_ROUTER_URL"] ))
def new_sandbox(): return client.create_sandbox( warmpool="python-sandbox-warmpool", namespace="agent-sandboxes", )
@pytest.fixture(scope="module")def sandbox(): sb = new_sandbox() yield sb sb.terminate()
def run(sb, command: str) -> str: return sb.commands.run(command).stdout.strip()
def can_connect(sb, host: str, port: int) -> str: return run( sb, f"timeout 3 bash -c '</dev/tcp/{host}/{port}' 2>/dev/null " "&& echo OPEN || echo CLOSED", )10.2 Is it really sandboxed?
def test_runs_under_gvisor(sandbox): assert "gVisor" in run(sandbox, "dmesg | head -n 20")
def test_is_not_root(sandbox): assert run(sandbox, "id -u") == "1000"
def test_has_no_kubernetes_token(sandbox): token = "/var/run/secrets/kubernetes.io/serviceaccount/token" assert run(sandbox, f"test -e {token} && echo YES || echo NO") == "NO"10.3 Can it reach things it should not?
BLOCKED = [ ("169.254.169.254", 80), # EC2 metadata ("169.254.170.23", 80), # EKS Pod Identity ("kubernetes.default.svc", 443), # Kubernetes API (os.environ["INTERNAL_TEST_HOST"], 443), # something in your VPC]
@pytest.mark.parametrize("host,port", BLOCKED)def test_cannot_reach(sandbox, host, port): assert can_connect(sandbox, host, port) == "CLOSED"10.4 Are sessions separate?
Write a file in one sandbox, then look for it from a second one.
def test_sessions_do_not_share_files(sandbox): run(sandbox, "echo secret > /workspace/leak.txt")
other = new_sandbox() try: found = run(other, "test -e /workspace/leak.txt && echo YES || echo NO") assert found == "NO" finally: other.terminate()10.5 Run them after every deploy
sandbox-tests: needs: deploy-staging runs-on: [self-hosted, staging-cluster] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.12" - run: pip install pytest k8s-agent-sandbox - run: pytest tests/test_sandbox.py -q env: SANDBOX_ROUTER_URL: ${{ vars.SANDBOX_ROUTER_URL }} INTERNAL_TEST_HOST: ${{ vars.INTERNAL_TEST_HOST }}Two tips:
-
INTERNAL_TEST_HOSTis the most useful test. Point it at a real service in your VPC that the sandbox must never reach, such as a database endpoint. It only passes if network policy is truly being enforced.
- Run the tests on a schedule too, not only on deploy. Node images and add-ons change without any deploy from you.
11. Running it day to day
Cost: how big should the warm pool be?
Every warm sandbox is a running pod. You pay for it even when nobody is using it.
- Too few, and users wait while a new node starts.
- Too many, and you pay for idle nodes all night.
Start with a small number. Measure how long a claim takes to become ready in your busiest hour, and adjust. If your users work office hours, lower
replicas at night with a scheduled job.Speed: what makes a cold start slow?
When the pool is empty, a new sandbox waits for four things: a node to launch, gVisor to install, the image to download, and the runtime to start. The node launch is the slowest. An AMI with gVisor and the sandbox image already inside removes two of the four.
Logs: where to look
From the node, a gVisor sandbox looks like one closed box. Node-level security agents cannot see the processes inside it. So log at the places you control:
- your backend: every tool call, with the user and session
- the router
- the Kubernetes audit log, for claims created and deleted
What to alert on
Signal | What it usually means |
|---|---|
Claims not ready after a few seconds | The pool is empty or nodes are not joining |
Sandboxes older than your longest session | Cleanup is failing somewhere |
Warm pool ready count below replicas | Sandboxes are failing to start |
Any pod in the namespace without gVisor | Someone changed the template |
You can turn the last row into a hard rule. Add a validating admission policy that rejects any pod in
agent-sandboxes without runtimeClassName: gvisor .Upgrades
- Pin the gVisor version and the node AMI version. Test new ones in staging first.
- A new AMI can bring a new containerd version, which changes the config line from section 5.
- agent-sandbox is still
v1beta1. Read the release notes before each upgrade.
- After any upgrade, run the tests from section 10.
12. The checklist
If you remember one thing: assume the code in the sandbox is hostile, then list everything it can reach.
- Agent code runs under gVisor (or Kata), on nodes used for nothing else.
- The platform team owns the template. The app can only create claims.
- One sandbox per session, deleted at the end, with an end time as a backup.
- Network policy is switched on in the VPC CNI, and the namespace blocks everything by default.
- No Kubernetes token, no AWS role, and the metadata address is blocked.
- You made a deliberate choice about DNS and internet access.
- Your backend treats sandbox output as untrusted.
- Break-out tests run on every deploy and on a schedule.
A sandbox does not make an agent safe. It takes one kind of failure, code doing something it should not, and keeps it inside one small room that you clean up afterwards.
References
- kubernetes-sigs/agent-sandbox : source, releases and examples
- agent-sandbox API reference : fields for Sandbox, SandboxTemplate, SandboxClaim and SandboxWarmPool
- agent-sandbox Python client : connection modes and usage
- Running Agents on Kubernetes with Agent Sandbox : the Kubernetes blog introduction
- Running gVisor on EKS with Karpenter : the node class approach used in section 5
- Limit Pod traffic with Kubernetes network policies : Amazon EKS User Guide
- Learn how EKS Pod Identity grants pods access to AWS services : Amazon EKS User Guide
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article