AWS Builder Center
Building AWS Nitro Sandboxes with Terraform: Hardware-Isolated Containers on Amazon EKS Auto Mode

Building AWS Nitro Sandboxes with Terraform: Hardware-Isolated Containers on Amazon EKS Auto Mode

Deploy EKS Auto Mode, run your own apps in microVMs with one YAML file each, make encrypted container images decrypt only inside an attested guest, and verify it all live, including what broke along the way.


Imagine running multiple AI agents on the same Kubernetes cluster. Each agent can generate code, execute commands, install dependencies, and interact with external services.
Now, what happens if one of those agents executes or produce malicious code? What happens if that code exploits a vulnerability in the container runtime or in the underlying host kernel?

A normal container is just a set of processes on the host's kernel. A vulnerability in that shared kernel ( Dirty Pipe  and  overlayfs  privilege-escalation bugs are well-known examples) can at some point allow a compromised workload to escape its container boundary and compromise other workloads on the same node.
Now, here is the real deal, AWS Nitro Sandboxes, launched in November 2026 for  EKS ,  ECS  and  EC2 , take a third path. Each pod can run in its own lightweight VM (a Firecracker microVM with its own guest kernel), managed by the Nitro Hypervisor, on a shared instance, at no additional charge. On EKS you just opt in with this one line:
spec:
runtimeClassName: isolated-sandbox # or confidential-sandbox
That one line is just the easy part. This guide is about everything around it:  identity ,  network policy ,  Pod Security ,  attestation , and making it reusable, so adding an app will just be one small file.



What You'll Build

By the end of this guide you will have:
  1. An Amazon EKS Auto Mode cluster (Kubernetes 1.36) in a private VPC, built with plain  Terraform .
  1. Two sample workloads running in Nitro Sandboxes: one  isolated , one  confidential  with a Cedar policy and KMS keys gated on attestation.
  1. Your own application running in a sandbox, defined by one YAML file, with its own IAM role. You can either deploy it with terraform, or you creates only its identity so you can deploy with  kubectl ,  Helm  or  GitOps .
  1. A bash script that runs nine live checks against the cluster to verify the sandbox.
  1. A clean teardown to avoid cost and charges.
Everything here was run by me against a real AWS account in  us-east-1 . The outputs are real outputs but I redacted the account IDs cause of security concerns. Whereever something did not work the first time, I say so and then show what I did to fix it.
Time: You should plan for about an hour; most of the apply is waiting for the EKS control plane. Cost: my dev cluster cost about $5/day (EKS cluster fee, one or two  c8a.large  nodes, a NAT Gateway). Destroy it when you're done (Check Section 9 for how to destroy it).



1. Isolated or Confidential sandbox? You decide based on the type of Trust



There are two types of sandboxes which are isolated and confidential sandbox
  •  isolated-sandbox  : This helps protects the node and other pods from the workload. You can use isolated sandbox for AI agents, generated code, CI runners and plugins. commands and things like  exec ,  logs  and  stats  will still work, and the overlay filesystem is unencrypted for faster startup.
  •  confidential-sandbox  : This helps protects the workload from the node and its operators. You can use confidential sandbox when workloads handle sensitive code, proprietary models, confidential data or customer workloads that must remain protected even from infrastructure administrators. A Cedar policy, generated from the exact pod spec, decides what operators may do; unlike  isolated , confidential sandbox denies commands like  exec . The writable layer and  emptyDir  sit on an encrypted overlay ( dm-crypt  over  dm-integrity ), and the parent instance can't read guest memory. The Nitro Secure Module measures the workload: PCR17 is the hash of the Cedar policy, and PCR8 identifies the guest image signer ( eks.amazonaws.com ). KMS key policies can require both.
Confidential mode does not automatically make every interaction with a workload private. Things like Logs, Pod Identity credentials, CSI-mounted secrets, shared storage, network traffic and other integration points still need deliberate security controls. The hardware isolation boundary is super important, but it doesn't means it replaces application-level secret management or careful design of operator access.
The rest of this article is about how to build and operate this, so that's all the theory you need.



2. My design Decisions (and Why I went it)

Before the steps, here is what I chose and the trade-offs.
  • Native Terraform, not the community EKS module. With Auto Mode, AWS manages nodes, AMIs, Karpenter and the core add-ons, which is much of what  terraform-aws-modules/eks  does already. Auto Mode also creates access entries for the cluster creator and node role itself; declaring them again fails with  409 ResourceInUseException . And the confidential KMS policy is subtle enough that I wanted every statement visible in one file. So the platform is a flat set of files:  vpc.tf ,  iam.tf ,  kms.tf ,  eks.tf ,  kubernetes.tf .
  • Two Terraform stacks: platform and apps. The platform ( platform/ : VPC, EKS, namespace, platform KMS key) with its terraform state and it is deployed once. Your apps ( apps/ ) are a second stack with their own state, which finds the cluster by name through data sources. I did this so that when adding an additional app, the terraform  plan  and  apply  will never refreshes, plans or touches the VPC, EKS or platform key, and app teams won't need any platform-level permissions before they can deploy successfully. I started with one stack though, in Section 8, Lesson 2, I explained further why I had split it.
  • One small local module for apps. The only module is  modules/sandbox-workload : everything one application needs. I create it for reuse: a new app means one module instance, not copy-pasted terraform.
  • Apps are YAML files, not one giant tfvars map. I noticed that eventually when I start having more than two apps, that file will get unmaintainably large. Now each app is  apps/<name>.yaml , which app teams can own without touching the terraform code.
  • Per-app IAM roles. Every app gets its own role, assumable only through EKS Pod Identity for this cluster. A compromised agent can use only the permissions you gave to the agent.
  • Terraform deploys the app, or only its identity. Many teams and organization already deploy with  Helm or Argo CD .  manage_deployment: false  makes Terraform create just the identity slot (IAM role, Pod Identity association, ServiceAccount, NetworkPolicy and, if it's a confidential sandbox, the app's KMS key too) and leaves the pods to them.
One KMS key per confidential app, for its encrypted images. Each confidential app gets its own small key whose policy only lets that app's role decrypt, and only with a matching attestation, which in practice means the AWS agent inside the guest decrypting the app's encrypted image. One app's mistake can't weaken another app's key.



3. Repository Layout

.
├── platform/ # STACK 1: deploy once
│ ├── vpc.tf # VPC, private/public subnets, NAT Gateway, KMS-encrypted Flow Logs
│ ├── iam.tf # Cluster role, Auto Mode node role, sample workload role
│ ├── kms.tf # Key for secrets/logs + PCR17/PCR8 statements for the sample workload
│ ├── eks.tf # EKS Auto Mode cluster, control-plane logging
│ ├── kubernetes.tf # Namespace (restricted PSS), default-deny NetworkPolicies, samples
│ ├── isolated.tfvars # Preset: isolated only
│ ├── confidential.tfvars # Preset: isolated + confidential (real PCR17 and Cedar policy)
│ ├── backend.tf.example # S3 remote state
│ └── tests/ # terraform test (mocked)
├── apps/ # STACK 2: your applications, own state
│ ├── hello-web.yaml # one YAML file per app (example.yaml.example lists every field)
│ ├── main.tf # finds the platform by name; one module instance per app
│ ├── backend.tf.example # S3 remote state (separate key)
│ └── tests/ # terraform test (mocked): the stack and the module
├── modules/sandbox-workload/ # Per app: IAM role, KMS key (confidential), Pod Identity,
│ # ServiceAccount, Deployment, Service, NetworkPolicy
├── examples/attestation-e2e/ # Manual end-to-end KMS attestation test
└── scripts/verify_sandbox.sh # Nine live checks of the platform



4. Deploy the Platform

Step 1: Prerequisites

  • Terraform >= 1.6 (I used 1.16.2), AWS CLI v2,  kubectl ,  jq ,  python3 
  • AWS credentials that can create  VPC ,  IAM ,  KMS  and  EKS  resources

Step 2: Clone and Pick a Preset

git clone https://github.com/Roslaan001/terraform-aws-eks-nitro-sandboxes.git
cd terraform-aws-eks-nitro-sandboxes

cd platform
cp confidential.tfvars terraform.tfvars # isolated + confidential, ready to use
# or: cp isolated.tfvars terraform.tfvars # isolated only
 confidential.tfvars  contains a real Cedar policy and PCR17 for the sample confidential image.  terraform.tfvars.example  contains placeholders; if you start from it, confidential pods will be rejected until you replace them.
For a team or production, use remote state first:
cp backend.tf.example backend.tf # in platform/ (and later apps/); S3-native locking needs Terraform >= 1.10
Also set  cluster_endpoint_public_access_cidrs  to your own network; my own defaults to  0.0.0.0/0 .

Step 3: Validate, Test, Plan, Apply

# still in platform/
terraform init
terraform fmt -check -recursive
terraform validate
terraform test # mocked; no AWS calls
terraform plan -out=tfplan
terraform apply tfplan
The tests run against mocked providers: 2 for the platform (Auto Mode settings, the restricted Pod Security Standard, the  RuntimeClasses ) and 12 for the apps stack (per-app roles, per-app KMS keys, standalone HCL inputs, and bad input such as an unpinned confidential image being rejected before anything is created).

Step 4: Connect  kubectl 

$(terraform output -raw kubeconfig_update_command) # in platform/
kubectl get runtimeclass
NAME HANDLER AGE
confidential-sandbox confidential-sandbox ...
isolated-sandbox isolated-sandbox ...
The  RuntimeClasses  comes bundled with EKS Auto Mode on 1.36. You don't create them. Nodes that can run sandboxes already carry the label  eks.amazonaws.com/nitro-sandbox=true . EKS Auto Mode gave me  c8a.large  nodes.

Step 5: Verify the Platform

The repository includes  scripts/verify_sandbox.sh , a verification script that runs nine checks against the deployed platform.
It validates RuntimeClasses, Nitro-capable node capacity, isolated and confidential workloads, Cedar policy enforcement, KMS authorization paths, workload IAM trust policies, and Pod Identity credentials.
Run it from the repository root:
./scripts/verify_sandbox.sh nitro-sandboxes nitro-sandbox-eks us-east-1
The script completed all nine checks successfully in my test environment.
Note: These checks validate the platform and its sample workloads. For per-application verification and the end-to-end KMS attestation test.



5. Deploy Your Own Application



This is the reusable part. Each app is one file in  apps/ , and the file name is the app name. All app commands run in  apps/ , a separate Terraform stack, so you never re-plan the platform code to add an app:
cd apps # from the repo root
terraform init # first time only

Option A: You let terraform deploys the App

# apps/hello-web.yaml
mode: isolated
image: public.ecr.aws/nginx/nginx-unprivileged:alpine
replicas: 2
port: 8080 # creates Service "hello-web"
allow_ingress: true # opens 8080 in the NetworkPolicy
run_as_user: 101 # nginx-unprivileged's UID
terraform plan -out=tfplan
# module.workload["hello-web"].aws_eks_pod_identity_association.this will be created
# module.workload["hello-web"].aws_iam_role.this will be created
# module.workload["hello-web"].aws_iam_role_policy.base will be created
# module.workload["hello-web"].kubernetes_deployment_v1.this[0] will be created
# module.workload["hello-web"].kubernetes_network_policy_v1.ingress[0] will be created
# module.workload["hello-web"].kubernetes_service_account_v1.this will be created
# module.workload["hello-web"].kubernetes_service_v1.this[0] will be created
Plan: 7 to add, 0 to change, 0 to destroy.
You can see nothing from the platform/ configurations appear in this plan: no  VPC , no  EKS , no  platform KMS key .
terraform apply tfplan
kubectl -n nitro-sandboxes rollout restart deployment/hello-web # first apply only, see below
Why the restart? To be honest, this surprised me, After the first apply, the pods were  Running  in  isolated-sandbox , but had no AWS credentials:
kubectl -n nitro-sandboxes get pods -l app=hello-web \
-o jsonpath='{.items[0].spec.containers[0].env[*].name}'
# (empty)
The Pod Identity association existed ( aws eks list-pod-identity-associations  showed it), but the EKS webhook injects credentials when a pod is created, and the association hadn't reached it yet. Terraform had even created the association first. After  kubectl rollout restart :
AWS_STS_REGIONAL_ENDPOINTS AWS_DEFAULT_REGION AWS_REGION AWS_CONTAINER_CREDENTIALS_FULL_URI AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE
I couldn't fix this with  depends_on , so the restart is a documented step. Terraform ignores the  restartedAt  annotation the restart adds, so it causes no drift.
Verify it's isolated, has its own identity, and serves traffic:
First of all, look at what the pod can see. A normal container sees the whole node; a sandboxed one sees its own small VM:
kubectl -n nitro-sandboxes exec deploy/hello-web -- sh -c 'grep MemTotal /proc/meminfo; nproc'
# MemTotal: 261268 kB <- ~255 MiB: the microVM
# 1

# For comparison: a normal (runc) pod on the same node type
kubectl run runc-cmp --rm -i --restart=Never -n default \
--image=public.ecr.aws/docker/library/busybox:1.36.1 \
--overrides='{"spec":{"nodeSelector":{"eks.amazonaws.com/nitro-sandbox":"true"}}}' \
-- sh -c 'grep MemTotal /proc/meminfo; nproc'
# MemTotal: 3895852 kB <- ~3.7 GiB: the whole c8a.large
# 2
Don't use  uname -r  for this. On Auto Mode the guest runs the same  Bottlerocket  kernel build as the node ( 6.18.56  on both), so checking the version tells you nothing. I made that mistake at first by comparing against my laptop's kernel. None of this proves hardware isolation; it shows the pod is in its own VM.
Next, check the identity:
I run a short-lived probe pod on the app's ServiceAccount:
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: Pod
metadata: {name: idprobe, namespace: nitro-sandboxes}
spec:
serviceAccountName: hello-web
runtimeClassName: isolated-sandbox
restartPolicy: Never
containers:
- name: probe
image: public.ecr.aws/aws-cli/aws-cli:2.27.50
command: ["aws", "sts", "get-caller-identity", "--query", "Arn", "--output", "text"]
env: [{name: HOME, value: /tmp}]
resources: {requests: {cpu: 100m, memory: 256Mi}, limits: {cpu: 500m, memory: 256Mi}}
securityContext: {allowPrivilegeEscalation: false, runAsNonRoot: true, runAsUser: 1000,
capabilities: {drop: [ALL]}, seccompProfile: {type: RuntimeDefault}}
EOF
kubectl -n nitro-sandboxes logs idprobe
# arn:aws:sts::<account>:assumed-role/nitro-sandbox-eks-hello-web/eks-nitro-sand-hello-web-...
kubectl -n nitro-sandboxes delete pod idprobe

kubectl run client --rm -i --restart=Never -n default \
--image=public.ecr.aws/docker/library/busybox:1.36.1 \
-- wget -S -O /dev/null http://hello-web.nitro-sandboxes.svc.cluster.local:8080/
# HTTP/1.1 200 OK
The client runs in  default  because  nitro-sandboxes  allows egress only to DNS and 443. The default-deny policy blocks communication on 8080 unless explicitly permitted.
To update the app, I edited the file and apply again. To remove it, you can delete the file and apply.

Option B: You let Terraform Creates the Identity, then You deploy with kubectl

# apps/kubectl-demo.yaml
mode: isolated
manage_deployment: false # Terraform: role, Pod Identity, ServiceAccount, NetworkPolicy only
port: 8080
allow_ingress: true
Plan: 5 to add, 0 to change, 0 to destroy.
Then the app team can deploy with any tool. The manifest must follow three rules, marked below. The restricted security context is required by the namespace.
apiVersion: apps/v1
kind: Deployment
metadata: {name: kubectl-demo, namespace: nitro-sandboxes}
spec:
replicas: 1
selector: {matchLabels: {app: kubectl-demo}}
template:
metadata:
labels: {app: kubectl-demo} # 1. matches the Terraform-managed NetworkPolicy
spec:
runtimeClassName: isolated-sandbox # 2. the sandbox
serviceAccountName: kubectl-demo # 3. the app's own IAM role
containers:
- name: web
image: public.ecr.aws/nginx/nginx-unprivileged:alpine
ports: [{name: app, containerPort: 8080}]
resources: {requests: {cpu: 100m, memory: 128Mi}, limits: {cpu: 500m, memory: 256Mi}}
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 101
capabilities: {drop: ["ALL"]}
seccompProfile: {type: RuntimeDefault}
---
apiVersion: v1
kind: Service
metadata: {name: kubectl-demo, namespace: nitro-sandboxes}
spec:
selector: {app: kubectl-demo}
ports: [{name: app, port: 8080, targetPort: app}]
kubectl apply -f kubectl-demo.yaml
The pod received credentials on its first start, and the probe returned  assumed-role/nitro-sandbox-eks-kubectl-demo . The Service answered  HTTP/1.1 200 OK .

What an App File Can Contain

mode: isolated # isolated | confidential
manage_deployment: true
image: <registry>/<repo>:<tag> # confidential: must be @sha256:<digest>
replicas: 2
command: ["/app/server"]
args: ["--listen", ":8080"]
env: {LOG_LEVEL: info}
port: 8080
allow_ingress: true
cpu_request: 100m
memory_request: 128Mi
cpu_limit: 500m
memory_limit: 512Mi
run_as_user: 10001
iam_policy_arns: [arn:aws:iam::123456789012:policy/my-app-s3] # this app only
iam_policy_json: '{"Version":"2012-10-17","Statement":[...]}'
kms_decrypt: false # isolated only
cedar_policy_base64: <genpolicy output> # confidential + managed
expected_pcr17: [<96 hex chars>] # confidential
Each YAML file is decoded into a typed Terraform object, where  optional()  provides defaults and validation blocks reject invalid configurations. The apps stack then discovers and processes every YAML file:
# apps/main.tf
data "aws_eks_cluster" "this" { name = var.cluster_name } # the platform, read-only

provider "kubernetes" { # configured from a DATA SOURCE
host = data.aws_eks_cluster.this.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.this.certificate_authority[0].data)
exec { /* aws eks get-token */ }
}

locals {
file_workloads = {
for f in fileset(path.module, "*.yaml") :
trimsuffix(f, ".yaml") => yamldecode(file("${path.module}/${f}"))
}
all_workloads = merge(local.file_workloads, var.workloads) # HCL entries still work
}

module "workload" {
source = "../modules/sandbox-workload"
for_each = toset(keys(local.all_workloads))
name = each.key
config = local.all_workloads[each.key]
# ...namespace, account, platform KMS key (for isolated apps that need it)
}
# modules/sandbox-workload/variables.tf (excerpt)
variable "config" {
type = object({
mode = string
manage_deployment = optional(bool, true)
image = optional(string)
replicas = optional(number, 1)
run_as_user = optional(number, 10001)
run_as_group = optional(number)
expected_pcr17 = optional(list(string), [])
# ...
})

validation {
condition = var.config.mode != "confidential" || !var.config.manage_deployment || (
can(regex("@sha256:[0-9a-f]{64}$", var.config.image)) &&
try(length(var.config.cedar_policy_base64) > 0, false) &&
var.config.run_as_group != null
)
error_message = "Managed confidential workloads need an image pinned by @sha256 digest, cedar_policy_base64, and run_as_group."
}
}
A confidential app with  image: nginx:latest  will at  terraform plan , before anything is created. The tests check exactly that. (The module also supports standard top-level HCL inputs—like  mode ,  image , and  replicas ; so direct Terraform callers don't have to wrap arguments in a  config  object or parse YAML).
Inside the module, each app's role trusts only EKS Pod Identity, for this account and this cluster (the account ID and region are auto-discovered from AWS data sources if at all I omit them):
# modules/sandbox-workload/main.tf
resource "aws_iam_role" "this" {
name = "${var.cluster_name}-${var.name}"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = { Service = "pods.eks.amazonaws.com" }
Action = ["sts:AssumeRole", "sts:TagSession"]
Condition = {
StringEquals = { "aws:SourceAccount" = local.account_id }
ArnEquals = { "aws:SourceArn" = "arn:${var.partition}:eks:${local.aws_region}:${local.account_id}:cluster/${var.cluster_name}" }
}
}]
})
}
The  provider "kubernetes"  block configured from a data source may look like just a mini detail, but that is what makes this layout work. In Section 8, Lesson 2, I explained why.



6. Confidential Apps: How Attestation Actually Works

The misconception I started with

My first assumption was thinking it worked like Nitro Enclaves: the app opens  /dev/nsm , gets an attestation document, and calls KMS itself. In an EKS confidential sandbox it can't. The generated admission policy allows no devices ( linux_devices.isEmpty() ),  /dev  inside the container is a  tmpfs , and AWS documents no attestation API for containers.
The attested call is made by the AWS agent inside the guest VM. The documented use is encrypted container images:
If KMS says no, the layers never decrypt and the container will never starts. The plaintext key exists only inside the guest.

The key policy: why explicit Denies

My first key policy had only an  Allow  conditioned on attestation. This may looks secure to you but I promise you, it's not: the standard account-root statement ( EnableIAMUserPermissions ) delegates to IAM, so any IAM policy granting  kms:Decrypt  to the role bypasses the condition. The way I fixed it is by two explicit Denies, one per measurement, evaluated independently:
# platform/kms.tf (sample workload; each app's own key in the module has the same shape)
{
Sid = "DenyConfidentialWorkloadMismatchedPCR17"
Effect = "Deny"
Principal = { AWS = aws_iam_role.workload.arn }
Action = ["kms:Decrypt", "kms:GenerateDataKey"]
Resource = "*"
Condition = {
StringNotEqualsIgnoreCase = { "kms:RecipientAttestation:PCR17" = var.confidential_expected_pcr17 }
}
},
{
Sid = "DenyConfidentialWorkloadMismatchedPCR8"
Effect = "Deny"
Principal = { AWS = aws_iam_role.workload.arn }
Action = ["kms:Decrypt", "kms:GenerateDataKey"]
Resource = "*"
Condition = {
StringNotEqualsIgnoreCase = { "kms:RecipientAttestation:PCR8:ServiceName" = "eks.amazonaws.com" }
}
},
{
Sid = "EnforceNitroAttestationForConfidentialWorkloads"
Effect = "Allow"
# ...both values must match (StringEqualsIgnoreCase)
}
An explicit  Deny  will override every  Allow : key policy, IAM or grant. And because negated operators match when the key is absent, a request with no attestation is denied too.
Each confidential app gets its own KMS key ( alias/<cluster>-<app> ), with its policy bound to that app's IAM role and expected PCR17/PCR8. During rollouts,  expected_pcr17  can contain both the old and new measurements:
expected_pcr17:
- <PCR17 of the current version>
- <PCR17 of the new version> # remove the old one once the rollout finishes
The platform key and application keys serve different purposes. The platform key ( alias/<cluster>-key , in  platform/kms.tf ) encrypts Kubernetes secrets (through the EKS cluster role) and the CloudWatch log groups. Its policy also restricts the sample workload role to attested requests; the sample image isn't encrypted, so in practice the sample makes no attested call. Each confidential application gets its own key ( alias/<cluster>-<app> , created by the module in the apps stack), whose policy references only that application's IAM role and its expected PCR17 and PCR8. App keys are not derived from or managed through the platform key, and apps never change the platform key's policy.

What attestation gates here, and what it doesn't

  • Demonstrated: attested decryption of encrypted container images. The AWS agent inside the confidential guest obtains the attestation document, calls  kms:Decrypt  with  Recipient , and unwraps the image-layer key inside the guest. This protects the contents of the encrypted image, including code, model weights, and configuration baked into its layers. The end-to-end test demonstrates this.
  • Not attested: application-initiated KMS calls. When an application calls KMS through the AWS SDK using its Pod Identity credentials, the request is not attested. Running inside a confidential sandbox does not change this, and the container cannot access  /dev/nsm  to attest itself. The explicit  Deny  statements above prevent the application from using  kms:Decrypt  and  kms:GenerateDataKey  on its own key. Therefore, that key protects the application's container images, not its runtime data.
  • Not implemented: runtime secret release. If an application needs secrets or data released only after proving its identity at runtime, an additional component, such as an attestation broker, must verify the guest and release the secrets. This project doesn't implement one. For runtime data, use normal IAM-scoped access, such as Secrets Manager through  iam_policy_arns , and treat that access as protected by the sandbox boundary and IAM, not by attestation.

Workflow for a confidential app

 PCR17  is the hash of the Cedar policy, and the policy is generated from the exact pod spec. Here is the full run for  conf-demo , a confidential nginx deployed through  apps/ .
1. Get genpolicy and verify it. Download the runtime archive and check the signature against the public key on the  download page :
for f in nitro-sandboxes-runtime.tar.gz SHA256SUM SHA256SUM.sig; do
curl -fsSLO https://d1uvmbvklg8rt.cloudfront.net/latest/x86_64/$f
done
openssl dgst -sha384 -verify nitro-sandboxes-runtime-v1.pub -signature SHA256SUM.sig SHA256SUM # Verified OK
sha256sum -c SHA256SUM --ignore-missing
tar -xzf nitro-sandboxes-runtime.tar.gz -C nsr/
2. Add the app with placeholders. Pin the image by digest and set the group explicitly (I explained why in step 5):
# apps/conf-demo.yaml
mode: confidential
image: public.ecr.aws/nginx/nginx-unprivileged@sha256:a77f1af2603df07bbf73221721393ab5d687de83462106937143e86460514f1e
replicas: 1
port: 8080
allow_ingress: true
run_as_user: 101
run_as_group: 101
cedar_policy_base64: pending
expected_pcr17: ["000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"]
3. Render the exact pod spec Terraform will deploy, without applying anything, and generate the policy:
# in apps/
echo 'yamlencode(module.workload["conf-demo"].manifest)' | terraform console | sed '1d;$d' > conf-demo.yaml
nsr/eks-nitro-sandbox-genpolicy --profile confidential --with-pod-identity \
--output-file-b64 policy.b64 conf-demo.yaml
--- Runtime Policy ---
// Runtime: exec is denied (no permit policy)
...
--- Predicted PCR17 ---
b2add91a5710c770c14ebb9cf4500714b6ea3ad9fdccbd55ba509b297c77078fffd27578ee30619a9fc2343f4e0520e4
The admission policy pins the image digest, user, group, capabilities, mounts and env vars. With  --with-pod-identity  it also requires the Pod Identity env vars and token mount.
4. Put  policy.b64  into  cedar_policy_base64  and the PCR17 into  expected_pcr17 , then terraform plan (in  apps/ ). You should expect the app's resources plus its own KMS key and alias, with the  PCR17  you just generated in the key's  Deny  and  Allow  statements to show. The platform won't be in the plan at all.
5. Apply, restart once, and verify. This took three attempts. Each failure is in Section 8, Lessons 2, 3 and 8. The working result:
kubectl -n nitro-sandboxes get pods -l app=conf-demo
# conf-demo-789c75f947-zjd5q 1/1 Running 0 (runtimeClassName: confidential-sandbox)

kubectl -n nitro-sandboxes exec deploy/conf-demo -- id
# ... policy denied Agent::Action::"Exec" on container "conf-demo"

KEY=$(aws kms describe-key --key-id alias/nitro-sandbox-eks-conf-demo --query KeyMetadata.KeyId --output text)
aws kms get-key-policy --key-id $KEY --query Policy --output text | jq -r '.Statement[] | "\(.Sid) \(.Effect)"'
# EnableIAMUserPermissions Allow (account root: keeps the key administrable)
# DenyWorkloadMismatchedPCR17 Deny (role/nitro-sandbox-eks-conf-demo)
# DenyWorkloadMismatchedPCR8 Deny (role/nitro-sandbox-eks-conf-demo)
# AllowWorkloadAttested Allow (role/nitro-sandbox-eks-conf-demo)
I did a probe on its ServiceAccount and it returned  assumed-role/nitro-sandbox-eks-conf-demo , the Service answered  HTTP/1.1 200 OK , and a later  kubectl rollout restart  was admitted. The restart annotation isn't part of the Cedar policy.
Two  genpolicy  details you should always remember:
  •  --with-pod-identity  is required if the pod uses Pod Identity, because the webhook adds a token volume after genpolicy reads the manifest.
  • genpolicy pins environment variables exactly. Kubernetes injects service-link env vars by default, so the module sets  enableServiceLinks: false .
Any change to the image, env, command, ports, resources or user/group changes  PCR17 . Don't forget to always treat  PCR17  as part of the deployment.

What I later proved live

I ran a real end-to-end test: a confidential pod with every image layer encrypted to a KMS key ( skopeo copy --encryption-key provider:awskms:<key> ). Full procedure in   examples/attestation-e2e/  .
Test
Result
Workload role calls the  kms:Decrypt  with no attestation
Denied:  AccessDeniedException ... with an explicit deny in a resource-based policy 
Real confidential pod, encrypted image
Succeeded: container logged  RESULT=PASS decrypted plaintext matches . CloudTrail recorded  attestationDocumentEnclavePCR17  = genpolicy's prediction and  attestationDocumentEnclavePCR8ServiceName = eks.amazonaws.com 
Same image + one extra env var (real  PCR17  change)
Denied:  StartError: prepare_image: KMS Decrypt failed: AccessDeniedException ... explicit deny 
Mismatched  PCR8 
Not testable live: This needs a guest image not signed by EKS. This was only covered by policy-structure checks




7. Cost

Nitro Sandboxes add no charge. What you pay for:
  • the EKS cluster fee ($0.10/hour),
  • the EC2 instances plus the EKS Auto Mode per-instance management fee,
  • the NAT Gateway ($0.045/hour plus data),
  • KMS and CloudWatch Logs.
Cost Explorer forecast about $5/day for my idle dev cluster. The day of the attestation test, with extra Auto Mode nodes, was about $6. The verification output in Section 4 was captured before I deployed any apps. Deploying the first one,  hello-web , made Auto Mode add a second  c8a.large  within seconds, and the cluster has run two nodes since.
The bin-packing win is real, but size it honestly. Compare equal total vCPU and memory, and include each microVM's overhead (its own kernel and agent) and the Auto Mode fee. Use the  AWS Pricing Calculator  with your own tenant sizes.



8. What Broke, and How I Fixed It

1. Two dependency cycles and a race, but I later split the stacks. I started with one stack: platform and apps together. Its Kubernetes provider was configured from the  aws_eks_cluster  resource, the cluster depends on the KMS key, and with shared-key statements the key policy needed each confidential app's role ARN. Every attempt to wire that up failed:
  • A Deployment  depends_on  its Pod Identity association: removing an app failed with  Error: Cycle , because the destroys is not in order.
  • The role inside the  for_each  module, read via  module.workload[k].role_arn  into the key policy: also a cycle. Referencing a module instance waits for the whole module, Kubernetes resources included.
  • A role ARN built as a string: no cycle, but no ordering either. Terraform updated the key policy before creating the role:
Error: updating KMS Key (...) policy: ... MalformedPolicyDocumentException:
Policy contains a statement with one or more invalid principals.
I assumed the AWS provider would retry but sadly, it didn't.
  • Putting the roles in the root module worked, but everytime there is an app change, it will still re-planned 68 resources and edited the shared platform key.
Here is what I did. I moved the apps moved into their own stack, whose Kubernetes provider is configured from a  data "aws_eks_cluster"  data source, so nothing in it depends on the platform's KMS key. This made room for a separate KMS key per confidential app inside the module, referencing the module's own role, with no cycle. I migrated the three live apps by moving their terraform state, not their resources. With local state, from the directory that held the old single-stack state:
Then  terraform plan  in both stacks showed only the intended changes: the new per-app key, tag updates, and the app statements leaving the platform key. No resource was re-created and no pod restarted.
2. The first pod and Pod Identity. For confidential apps, the race is worse: Cedar requires the Pod Identity environment variables, so the pod is rejected if they are missing.and  terraform apply  times out waiting for the rollout. Option A is to restart once or go with option B which is to create the identity before the pods exist.
3. genpolicy pins everything.  enableServiceLinks: false ,  --with-pod-identity , and digest-pinned images. When encrypting images with  skopeo , stage them as a gzip OCI layout first. Encrypting straight from local container storage produced  blob digest mismatch  inside the guest.
4. Give sandboxed pods real memory. An  aws sts get-caller-identity  pod with no resource requests was giving me  OOMKilled  (exit 137).
5. CloudWatch Logs needs its own KMS statement. Encrypting log groups with your key needs a key-policy statement for  logs.<region>.amazonaws.com  with a  kms:EncryptionContext:aws:logs:arn  condition, or  apply  fails with  AccessDeniedException .
6. Auto Mode wants  bootstrap_self_managed_addons = false , and the compute, block-storage and load-balancing flags must all match. Otherwise, you will get:  InvalidParameterException: When EKS Auto Mode is enabled, bootstrapSelfManagedAddons must be set to false. 
7.** Set  runAsGroup  for confidential pods.** Even with credentials injected,  conf-demo  was still denied at  CreateContainer . Regenerating the policy from the Deployment as stored in the cluster gave an identical policy, so the manifest was right and the difference had to be at runtime. Diffing against the sample's working policy showed my policy pinned  run_as_group == 0 . With  runAsGroup  unset, genpolicy assumes group 0, but the runtime uses the image's group for user 101 (also 101). Two throwaway pods settled it: with  runAsGroup: 101  set, the pod was admitted; with only the env pinning relaxed ( --allow-additional-env ), it was still denied. The module now requires  run_as_group  for managed confidential apps and fails at  plan  without it.
9. A failed create can corrupt provider state. After the rollout timeout, every plan failed with  Unexpected Identity Change  on the Deployment, a kubernetes provider bug. I had to manually run  terraform state rm  the Deployment and  terraform import  it again ( nitro-sandboxes/conf-demo ). Nothing in  state rm  and  import  touch or make the cluster change.



9. Clean Up

Destroy the apps stack first, then the platform. The other way round leaves app IAM roles and KMS keys behind, and the apps stack can no longer reach the cluster to clean up.
kubectl delete deploy,svc kubectl-demo -n nitro-sandboxes # Option B apps (optional)

cd apps
terraform plan -destroy -out=destroy.plan && terraform apply destroy.plan # app roles, keys, objects

cd ../platform
terraform plan -destroy -out=destroy.plan && terraform apply destroy.plan # EKS, VPC, platform key

cd .. && make clean # from the repo root: removes .terraform/, *.tfstate*, *.plan and tfplan under platform/ AND apps/. Only after both destroys!
App KMS keys are scheduled for deletion (7-day window), so they will not be deleted immediately.
If you created encrypted images or a test KMS key for the attestation test, you need to delete the ECR repository and schedule the key for deletion:
aws kms schedule-key-deletion --key-id <test-key-id> --pending-window-in-days 7



So yeah, thank you for reading all through, see you in the next one!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article