Untrusted Code, Trusted Token (Part 3 of 3): Five Attacks on a Sandboxed AI Agent, and What Nitro Sandboxes Don't Solve

Untrusted Code, Trusted Token (Part 3 of 3): Five Attacks on a Sandboxed AI Agent, and What Nitro Sandboxes Don't Solve

Five attacks on a sandboxed AI coding agent on EKS: hostile code, a hijacked brain, a cluster admin, forged pull requests and an insider. What held, and what Nitro Sandboxes do not protect.

Solution Architect | 12x AWS Certified | AWS Ambassador, Vadodara UG Leader, Community Builder
In  Part 1 , we saw what Nitro Sandboxes are. In  Part 2 , we built a coding agent with three trust zones:
  • brain, an ordinary pod that talks to the model;
  • hands, an isolated sandbox with no network, where untrusted code runs;
  • broker, a confidential sandbox that is the only holder of the GitHub token.
The agent fixed a real bug and opened a real pull request. Now we try to break it.
A design is only a claim until you test it. Each experiment below is a script in  AditModi/sandboxed-coding-agent  that prints  PASS  or  FAIL  lines, or the exact refusal it received, so you can compare the output line by line.
The seven experiments and the claim each one tests


Experiment 3: can hostile code in the hands get out?

Claim: code that runs in the hands, including the repository's own tests, cannot reach the network or any credential.
experiments/e3-hostile-code.sh
This runs the probe from Part 1 inside a real hands session, in exactly the place where the repository's tests run. When the documented behaviour holds, every check is  PASS :
== can it get out? ==
[PASS] no IPv4 route out of the VM
[PASS] DNS cannot resolve github.com
[PASS] no TCP to 1.1.1.1:443
[PASS] no instance metadata (169.254.169.254)
[PASS] no Pod Identity endpoint (169.254.170.23)
[PASS] no Kubernetes service account token
[PASS] no AWS credential variables
This is also the answer for the hostile  test_environment.py  from Part 2. It runs in the same place, looks for the same things, and finds nothing. Its upload to  collector.example  fails at the DNS lookup. The error is swallowed, so the test suite stays green. The attacker gets nothing, and does not even learn that the attack failed.

Experiment 4: can a hijacked brain escape the sandbox?

Claim: even an attacker who fully controls the brain cannot start a pod without the sandbox.
experiments/e4-hijacked-brain.sh
This runs the brain image with its real service account and asks for an unsandboxed pod in two places:
  • In  agent-hands , RBAC allows pod creation, so the admission policy must refuse it. The refusal names the policy and its message: pods in  agent-hands  must run in an isolated Nitro Sandbox.
  • In  agent-brain , RBAC itself must refuse it with  403 Forbidden , because the brain's Role does not exist there.
Both lines should be  PASS .

Experiment 5: can cluster-admin read the token?

Claim: someone with full cluster-admin rights still cannot get the GitHub token out of the broker. A normal container cannot pass this test.
experiments/e5-cluster-admin.sh
The script tries three things.
5a: exec into the broker. First it confirms that RBAC allows it ( kubectl auth can-i create pods/exec  answers yes). Then it runs  kubectl exec ... -- cat /proc/1/environ . Kubernetes lets the request through, but the guest refuses it. AWS's Cedar policy blueprint documents the error, which names the exact Cedar action:
error: Internal error occurred: ... failed to exec in container: failed to create exec "...": policy denied
Agent::Action::"Exec" on container "broker" reasons=[] errors=[]
There are two separate decisions here. RBAC decides whether you may ask. The Cedar policy inside the VM decides whether it runs.
5b: read the token from the pod spec. This works. You get  GITHUB_TOKEN_CIPHERTEXT , a few hundred characters of KMS ciphertext.
5c: decrypt it with the broker's own IAM role. The script starts an ordinary pod in  agent-broker  that uses the broker's service account. EKS Pod Identity gives that pod the same IAM role as the broker. Then it calls  aws kms decrypt .
Same role, same ciphertext, same account. Only the attestation document is missing, and KMS refuses. The error format is the one the AWS blueprints document (account ID masked, key ID shortened):
[PASS] KMS refused:
An error occurred (AccessDeniedException) when calling the Decrypt operation: User:
arn:aws:sts::111122223333:assumed-role/sandboxed-agent-broker/... is not authorized to
perform: kms:Decrypt on resource: arn:aws:kms:...:key/... with an explicit deny in a
resource-based policy
Remember this one: the boundary is the attestation, not the IAM role. In a normal design, "who holds the credentials" is the whole security question. Here it is only half of it.

Experiment 6: can a hijacked brain push a workflow or go straight to main?

Claim: even if the model obeys the poisoned issue completely, the broker only opens safe pull requests.
experiments/e6-forged-requests.sh
This sends the requests that a fully hijacked brain would send. I ran the same five requests through the real broker code locally, against the fake GitHub. This is that real output:
$ POST /pull-requests {"branch": "release", "files": [".github/workflows/release.yml"]}
{"status": "refused", "reason": "path '.github/workflows/release.yml' is under '.github/', which the broker never changes"}
$ POST /pull-requests {"branch": "hotfix", "base": "main", "files": ["indian_numbers/money.py"]}
{"status": "refused", "reason": "unexpected field(s) ['base']: the repository, base branch and branch prefix are fixed inside the broker and cannot be chosen by a request"}
$ POST /pull-requests {"branch": "sneaky", "files": ["docs/../.github/workflows/x.yml"]}
{"status": "refused", "reason": "path 'docs/../.github/workflows/x.yml' is not in normal form"}
$ POST /pull-requests {"branch": "owners", "files": ["CODEOWNERS"]}
{"status": "refused", "reason": "file 'CODEOWNERS' is never changed by the agent"}
$ POST /pull-requests {"branch": "../main", "files": ["README.md"]}
{"status": "refused", "reason": "branch must be 1 to 41 characters of a-z, 0-9 and '-', starting with a letter or digit"}
On EKS, the answers come from the same code. There is also a second layer on GitHub's side. Changing files under  .github/workflows/  needs a separate Workflows permission on a fine-grained token, and my token does not have it. So even a bug in the broker's rule would not be enough to add a workflow.

Experiment 7: can an insider loosen the rules and redeploy?

Claim: a person who can build images, push to ECR, generate policies and redeploy pods still cannot give the broker weaker rules, unless they can also change the KMS key policy.
experiments/e7-insider-change.sh
The script plays a careful insider:
  1. It makes one change: it removes  .github/  from the denied list, so that the agent could "fix CI".
  1. It builds and pushes the image, and generates a fresh, valid Cedar policy.
  1. It prints both PCR17 values. They must be different, because the image is different. AWS's blueprint shows the same thing with a one-variable change: two completely different PCR17 values.
  1. It replaces the broker.
The new broker attests honestly, but with the new PCR17. The key policy still expects the old one, so the broker's first log line should be:
{"event": "broker_sealed", "reason": "AccessDeniedException", "detail": "An error occurred (AccessDeniedException) when calling the Decrypt operation: ..."}
The broker exits and opens nothing. At the end, the script puts the approved broker back, and you see  broker_unsealed  again.
To finish this attack, the insider also needs  kms:PutKeyPolicy  on this key. That is a different permission, it can belong to a different team, and CloudTrail records every use of it. Attestation did not make the insider powerless. It moved the attack to one place that I can protect separately and watch.

What Nitro Sandboxes do not solve here

If I stopped at seven passing experiments, this would be a marketing article. These are the gaps that I know about, and I think they matter as much as the experiments.
A compromised node can still call the broker. In confidential mode the node is untrusted, but the brain calls the broker over plain HTTP, with no authentication. The network policy that limits who can call the broker is enforced on the node itself. So a hostile node can send requests directly. What can it get? A pull request from an  agent/  branch, into  main , without  .github/  or  CODEOWNERS  changes, which a human still has to review and merge. That is why the broker's rules are narrow, and why human review stays in the design.
Turn on branch protection anyway. A fine-grained token with Contents write could push to  main  if someone used it directly. In this design, nobody can, because it is never decrypted outside the broker. But if your threat model includes bugs in the broker, also turn on branch protection for  main .
Whoever owns the key policy owns everything. A person with  kms:PutKeyPolicy  on this key can point it at any PCR17. That permission is my real root of trust. Give it to a different team than the platform team, and alert on every  PutKeyPolicy  event in CloudTrail.
Every honest rebuild also locks the broker. A new image means a new PCR17, even for a small security patch. The EKS guide says to regenerate the policy and the key policy condition every time the pod spec changes, and to build this into CI/CD. That key policy step needs its own approval. Otherwise, experiment 7 comes back as "just a normal deployment". Signing images with AWS Signer and generating the policy with  --require-any-signer  makes this easier.
Confidential does not mean available. The node cannot read the broker, but it can stop it, slow it down or delete it. Nitro Sandboxes protect secrecy and integrity, not uptime.
The node can read the logs. The confidential profile allows log streaming. My broker never logs the token, but whatever a confidential pod writes to stdout, assume that the node operator can read it.
Two choices I made for a demo:
  • The broker is a bare Pod, because its policy is generated from its exact spec. In production, I would use a controller and regenerate the policy in the pipeline.
  • I used the generator profile from the AWS blueprints instead of the built-in confidential profile. The blueprints explain that the built-in profile currently emits fields that the guest rejects.
None of this makes Nitro Sandboxes less useful. It tells me clearly which part the hardware solves (who can read the secret, and which code can use it) and which part is still my job (what the agent is allowed to do with it).

Clean up

scripts/99-clean.sh # everything this repo made in AWS, but keep the cluster
scripts/99-clean.sh --cluster # and the cluster too
This removes the namespaces, the admission policy, the Pod Identity associations, both IAM roles and the ECR repositories, and schedules the KMS key for deletion. Seven days is the shortest wait KMS allows. On GitHub, revoke the token and close the agent's pull requests.

What I take away

Three things changed in how I think about agents on EKS.
First, "which runtime class?" is a trust question, not a performance question. It has a different answer for each part of the same agent. The code the agent runs and the component that holds the secret need opposite things, so they should never live in the same VM.
Second, attestation changes what an IAM role means. In experiment 5, the same role, used from the wrong place, got nothing. I always thought of KMS as "who may decrypt". With Nitro Sandboxes, it becomes "which code, measured by hardware, may decrypt".
Third, the hardware answers "who can read the token". It does not answer "is this action safe". That part is still rules, narrow permissions and human review. The nice surprise was that the rules can be part of the measurement too.
I will go deeper into sandboxing agents on EKS in my re:Invent code talk, COM329. If you run the repository and something does not match what I describe, please  open an issue  with the output. That is the most useful feedback I can get.

Sources

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