Hardware-Isolated AI Agents Using AWS Nitro Sandboxes on EKS

Run untrusted, agent-generated code inside dedicated hardware microVMs on shared EC2 nodes—eliminating noisy-neighbor leaks without provisioning separate instances per user.

student
Modern AI agents do more than answer text prompts. They write Python scripts, parse untrusted spreadsheets, and execute shell commands on the fly. Giving an autonomous agent a shell inside a standard container creates a hard infrastructure problem: traditional Linux containers share the host kernel. If an agent runs malicious or buggy generated code, a single kernel exploit puts every co-located tenant on that node at risk.
Spinning up a dedicated EC2 instance per agent session solves the isolation problem, but destroys unit economics and leaves you waiting minutes for instances to boot.
With the launch of AWS Nitro Sandboxes in November 2026, AWS bridges that gap. You can now give individual Amazon EKS pods or Amazon ECS tasks their own hardware-enforced VM boundary while packing multiple workloads onto a single EC2 instance—at zero additional charge beyond standard EC2 and EKS/ECS fees.
Here is how Nitro Sandboxes work, how to choose between isolated and confidential modes, and how to wire them into an agentic code-execution pipeline.

Isolated vs. Confidential Mode: Choosing Your Boundary

AWS Nitro Sandboxes offer two hardware-backed security profiles depending on the sensitivity of the data your agents touch:
Capability
Standard Containers
Nitro Sandbox (Isolated Mode)
Nitro Sandbox (Confidential Mode)
Kernel Boundary
Shared host OS kernel
Dedicated guest kernel per pod/task
Dedicated guest kernel + encrypted memory
Neighbor Protection
Namespace / cgroup isolation
Hardware hypervisor isolation
Hardware isolation + zero node-operator access
Cryptographic Attestation
None
Standard IAM / KMS controls
Hardware attestation before secret release
Additional AWS Fee
None
$0 (included on supported EC2)
$0 (included on supported EC2)
Best Used For
Trusted internal microservices
Untrusted agent code & CI/CD runners
Regulated PII, finance, and multi-party models
A practical rule: use Isolated Mode whenever an agent executes LLM-generated code or processes untrusted user files, and step up to Confidential Mode when the sandbox must decrypt sensitive customer records using cryptographic attestation.

The Pipeline Architecture

  1. Generate Code via Amazon Bedrock: A foundation model (such as OpenAI GPT-6.2 Astra or Claude Fable 5.2 on Bedrock) writes a Python script to analyze user-uploaded data.
  1. Dispatch to a Sandboxed EKS Pod: Your orchestrator schedules a short-lived Kubernetes pod annotated with the Nitro Sandbox runtime class.
  1. Execute Inside a Hardware MicroVM: The pod boots its own lightweight guest kernel on the shared EC2 host, runs the script with strict network egress blocks, and writes output artifacts to a scoped Amazon S3 prefix.
  1. Tear Down Cleanly: Once execution finishes, the microVM terminates, wiping guest memory completely before the host reclaims capacity.

What You Need

  • An Amazon EKS cluster running EKS Auto Mode (or ECS Managed Instances) on Nitro-based EC2 instances
  •  kubectl  configured with permissions to deploy  RuntimeClass  pods
  • Python 3.11+ with  boto3  and access to an Amazon Bedrock foundation model

Step 1: Define a Sandboxed Kubernetes Pod Spec

Instead of refactoring your container images, you enable hardware isolation at the pod specification level by targeting the Nitro Sandbox runtime class and locking down Linux capabilities.
YAML
apiVersion: v1
kind: Pod
metadata:
name: agent-code-runner
namespace: ai-sandboxes
spec:
runtimeClassName: aws-nitro-isolated
restartPolicy: Never
automountServiceAccountToken: false
containers:
- name: python-sandbox
image: public.ecr.aws/docker/library/python:3.11-slim
command: ["python", "-c"]
args:
- |
import os, json
# Execute agent-generated logic inside a hardware-isolated guest kernel
data = [12, 45, 67, 23, 89]
result = {"mean": sum(data) / len(data), "max": max(data)}
print(json.dumps(result))
resources:
limits:
cpu: "1"
memory: "1Gi"
securityContext:
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false

Step 2: Generate and Dispatch Safe Execution from Python

Keep the model generation layer completely separate from the execution layer. Your orchestrator calls Amazon Bedrock's  Converse  API to produce code, validates basic syntax, and dispatches the payload to the isolated sandbox.
Python
import ast
import json
import boto3

REGION = "us-east-1"
bedrock = boto3.client("bedrock-runtime", region_name=REGION)
MODEL_ID = "anthropic.claude-fable-5-2-v1:0"

def generate_analysis_script(user_request: str) -> str:
response = bedrock.converse(
modelId=MODEL_ID,
messages=[{
"role": "user",
"content": [{
"text": (
"Write standalone Python code using only the standard library "
"to solve this task and print valid JSON to stdout. "
f"Output code only, no markdown fences.\n\nTask: {user_request}"
)
}],
}],
inferenceConfig={"maxTokens": 600, "temperature": 0.1},
)
code = response["output"]["message"]["content"][0]["text"].strip()

# Catch syntax errors before spinning up a sandbox pod
ast.parse(code)
return code

script = generate_analysis_script("Calculate moving averages for [10, 20, 30, 40, 50] with window 3.")
print("Validated script ready for Nitro Sandbox dispatch:\n", script)

Responsible Use, Security, and Cost Guardrails

  • Block Outbound Egress by Default: Hardware isolation prevents a rogue script from escaping to the host EC2 instance, but it does not stop the script from making outbound network calls unless you enforce Kubernetes  NetworkPolicy  rules or VPC security groups. Restrict egress strictly to required VPC endpoints.
  • Set Hard Execution Timeouts: Agent-generated code can easily enter infinite loops. Always enforce  activeDeadlineSeconds  (for example,  30  seconds) on sandbox pods so runaway tasks terminate automatically.
  • Disable Service Account Token Automounting: Set  automountServiceAccountToken: false  on every code-execution pod so untrusted scripts cannot query the Kubernetes API server.
  • Watch Model Data-Retention Policies: Certain newly released Bedrock models enforce model-specific traffic retention rules for abuse detection.Check the current Bedrock documentation before routing regulated customer payloads through newly onboarded models.
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