Post

straightjacket: An infrastructure-level AI sandbox harness

Continuing on from my previous blog post, here is a demonstration of a technical implementation, albiet still a proof of concept.

What is it?
It’s a fancy kubernetes cluster. Its an infrastructure harness for AI sandboxing. Deploy any container, and I have syscall-equivalent level monitoring and comprehensive network monitoring and control. You can pause workloads on suspicious activity, and resume when you deem its safe to do so. You can also snapshot entire workloads in milliseconds for offline processing and forensic investigation.

I want to stress that this is a concept and not a product. Many people turn try and sell these types of things. I want to share the idea here, and demonstrate how these technologies can work together in unison to provide a powerful capability. Do not run this against any real workloads - its not ready for that and I make no claims to its testing coverage and maturity.

The core concept around this project is to give an AI system fewer restrictions (like tool calls, internet access) by having more control over the infrastructure it runs on. I appreciate sounds counter intuitive; but its not about enforcing specific access to tools, or adding guardrails, or LLM gateways. I dont really want to interfere that high up the stack. I’ve created a generic infrastructure harness, which is completely agnostic to any model, SDK or software you want to run. The only requirement is your stuff needs to be in container(s), so it can get scheduled on the cluster.

I call the project straightjacket. I envision its primary use case for evaluation environments, or testing environments for agent swarms against open infrastructure. Its overkill for coding agents.

You may have seen all the ARTEX attacks hitting the news in the last couple of weeks. I’m not sure its good enough anymore to test agents & swarms in conveniently locked-down environments. You need to test against the real thing, just like threat actors do. This concept would enable operators to think and act like an attacker, but with consideration of causing damage and hopefully avoiding more huggingface-type incidents.

For the first time ever, I’ve actually edited a video demonstration. The first few minutes show the idea E2E, and the remainder of the video shows off some scenarios and flexing some of the capabilities. I’d suggest jumping to the testing & demonstration section of this blog, and clicking the timestamps to any sections which sound interesting. If you are going to check out anything, I’m particularly happy with the workload control demonstration.

The code is available here, and there is some living documentation here. I think I’m going to continue working on this project, so expect to see plenty of updates and stability improvements.

Straightjacket

straightjacket’s design philosophy is not about maximum restrictions over an AI workload. Instead, is about extensive monitoring and fingerprinting and providing comprehensive control over a sandbox. That might sound like an oxymoron, but there is nuance in the wording.

I believe, that in order to truely evaluate AI models/agents for cyber security, we need to give them representative capabilities that a threat actor has. Existing benchmarks are way off the mark in answer to that question. Often they openly have restrictions about what they test, are product specific, have super specific (and limited) objectives or oversimplify an attackers arsenal, by just giving them a Kali box.

Straightjacket shifts the problem earlier (shifts left?) into the harness. By creating a heavily monitored, model/harness-agnostic runtime engine, it shifts the problem to a high-volume data processing pattern. Can I detect the early signals that my agent is up to no good, and pull the plug on it before it does any damage?. For me, the biggest risk is that agents steps outside my boundry of control, by self-replicating or via covert communication.

Obviously monitoring is retrospective (even if its in near real time), and an AI systems’ damage may already by done by the time a signal is caught and processed. The idea here is we have strong preventative controls in place already (excluding any tool-level type restrictions), and the detection controls here are secondary to help fuel further preventative controls.

I think there is an argument that hypothetically, a combination of network, system and application signals (tcp/ip, syscall, decrypted https etc…) with near real time processing is enough to catch malicious activity before it completes. The problem is of scale, and having the ability to process fast enough to act appropriately. An implant, brute force, lateral movement, self replication… would result in thousands of signals in the network or stack (file opens, socket connections etc…).
This project is a step towards testing that hypothesis.

People are already unleashing extremely capable frontier model/agent swarm on the open internet or at a real targets. I think self-limiting evaluation environments exhibit excessive paranoia at the expense of truely guaging capability, which impacts security preparedness. I feel like the huggingface incident has the industry scared, and has potentially put defenders on the back foot for effective evaluations.

OpenAI recently have said they do not allow their models access to the internet for training and evaluation. I never know how much of the frontier companies articles are hype vs reality, as they are not impartial parties when gauging their products cyber capabilities.

A truely independent actor might conclude that the paranoia is unfounded. A question I have is: Does an LLM need to take over the world before we know if its capable of taking over the world? How do you measure capability vs potential? and does it matter?

Those are problems for another day. For now, I’m going to focus on gathering the most signal as possible, as early as possible.

I want to see if I can create a kind of tripwire AI system where its impossible to perform a nefarious action without me knowing about it.

alt text

Architecture

Straightjacket is intentionally designed, but execution is obviously AI-driven. I hope that the clearly AI-generated code/applications don’t deter you from taking a look. What a world we live in where I can single-handedly put a system like this together in a few weeks.

I appreciate there is a lot here, I explain it in the demonstration, but I’ll also explain it briefly here. (There is also a more detailed (AI generated) architecture diagram available in the companion app and in the code base).

Before I get into it, when I say workloads, I mean the AI systems, swarms, agents, models that will be running on the harness. When is say fingerprinting, I really mean comprehensive signal gathering.

Originally, as inspired by my old AKS-ebpf integration blog post, i was drawn to using Cilium & Tetragon for all the fingerprinting and security policy enforcement for the workloads. But the whole “a container isnt a sandbox” and gVisors nested isolation and pause/resume/snapshot capability is just too enticing.

Although tetragon is present in this system, I am not using it for pod/container inspection. Instead, I’m using gVisor and collecting its runtime logs with a custom collector (as falco support has been dropped ☠). I lose the policy enforcement from tetragon, but still gain runtime telemetry, gain the nested isolation, and gain the use of runsc’s pause/resume features for pausing a sandbox if a signal looks suspicious. This is integrated into an independent data processing system*immature, which buys me time for my LLM-as-a-judge and/or other processing to perform a deeper analysis and decision, and then resume the sandbox if no further action is required. In addition, i can use gvisors checkpoint/restore functionality to take periodic snapshots of the sandbox and containers, which i can then pass over to offline-processing engines, to help build a SBOM, inspect memory, or just keep a forensitc snapshot of whats going on! 🔥

An Azure Kubernetes Service (AKS) cluster is deployed in bring your own CNI mode (BYOCNI), where I setup and use Cilium and Tetragon. So the workload nodes are eBPF powered, and I create baseline policies that capture all network traffic, as well as syscalls. It’s all policy driven, so you can fine tune the level of signal based on your needs.

For the workloads pods, I’m not using the native runtime. This is where I’ve swapped in gVisor and runsc. This nested isolation means that tetragon monitoring and protection is effectively blocked within those pods, as gVisor has its own isolation that hides visibility into the workloads. Thats not a problem though, because gVisor has its own SecCheck which gives me the syscall insight if i need it.

gVisor has essentially re-created the Linux kernel interfaces natively, so its not quite got feature parity or telemetry depth that I’d get running tetragon directly for the containers.

Although gVisor blocks a lot of those low-level eBPF insights into the workload, I’m still using gVisor and eBPF on the underlying node. gVisor sandbox to sandbox communication, and external communication still needs to travel through the node, so I can get these insights there. As i’ve talked about before, im not super comfortable conceedeing control to network management to a managed service like Azure firewall. I want fine grained control, which is what I can get with Cilium network policies for IP filtering, DNS filtering and a stateless/stateful firewall type functionality.

Essentially any time a pod running in gvisor needs to talk to another, it goes to the node level, through the eBPF controls and back out. The eBPF programs are loaded into the kernel via the cilium agent, which reads the policies and then loads the eBPF app as appropraite.

If the policies are configured, cilium can route L7 traffic via an envoy proxy, which I’ve configured with optional TLS inspection. Custom PKI is generated using cfssl and uploaded to a key vault. It’s actually a bundle of certificates, including public certs. The issue is that with TLS inspection, the workloads need to trust the certificate. But i want this to be an agnostic harness and not dictate any code changes to read my custom certs. I cant assume that every workload is like an ubuntu linux, so what I’m doing is uploading the cert bundles at a bunch of well know paths like:

1
2
3
4
5
/etc/ssl/certs/ca-certificates.crt
/etc/pki/tls/certs/ca-bundle.crt
/etc/ssl/ca-bundle.pem
/etc/pki/tls/cacert.pem
...

Application libraries (like golang), typically check these locations for cert bundles by default. So by mounting the bundle to these location, i get a kind of best-effort agnostic TLS inspection capability. The bundle mount works by using the Azure Key Vault provider for k8s secrets Container Storage Interface (CSI) to integrate the key vault with the AKS cluster. Kyverno admission controller essentially processes incoming pod requests, updates the manifest on the fly with the mount, before kubelet schedules the pod.

It’s kind of tricky, because i want this to be an infrastructure harness, but the TLS inspection starts at the application layer, so the above is a reasonable compromise for enforcing any application-level dependencies. But seeing as its running k8s, most containers will be linux based, so the above should work. If you’re running binaries direct in scratch containers, I can assume the base runtimes like golang or rust would honor those paths.

Tetragon still has a place, but its security policies are at the node level, not pod level. I’ve crafted a few policies for sensible defaults, including opt-in syscall capture at that level for trace/debug/info/warn type levels.

So at a high level, thats kind of how it all works! Lots of complementing pieces of tech working together to provide a fine-grained but generic(ish) sandboxing infrastructure harness.

Any auto-scaling events will just work, so its AI swarm friendly! 🚀

Why not just monitor the inference?
This might be over-engineered, can you just monitor the inference and cut off the LLMs brain at source?
Ignoring all the requirements I set out previously, and any defence in depth arguments, I think the biggest counter argument to this point is context and processing. It’s absolutely a critical signal to gather and process, but often LLMs will use their inference to generate scripts and code, and execute the code against a target. If an agent is generating a test.sh file, its going to be fiddely to process the inference with enough confidence to know whether that is a malicious script or a legitimate local file. Of course, thats the eventual aim with this system, but being able to correlate signals from inference, and the syscalls, and the network traffic may help to triangulate the signal to determine its intent, and determine the appropriateness of our response.

The TLS inspection is the only element which I’m not really happy with, as its goes against the principle of being an infrastructure harness, which is agnostic of whats running. I need to be able to trust certificates for TLS inspection. I can assume that the workload will exercise common env variables or the injected mounted paths like I’m doing, but its not ideal. It’s as hands-off and agnostic as I think I can make it. If you have a better approach, please let me know.

However, you seriously should use TLS inspection in your sandboxing. The other week, a colleague noticed that OpenAI’s web_search tool call is proxied through api.openai.com. So in an environment where all domains were restricted to stop internet access, the inferencing API (which is allowed) is used to provide unrestricted internet access to the agent! OpenAI suggest using some specific settings to opt-in to disable external website or allowlist domains that they will honor in their proxying. I really don’t like the application-specific configuration and trust me bro-ness of that approach.

So although its a little heavy, at least with TLS inspection you get that full insight that allows you to make informed decisions.

Credential Injection

One of the many items on my wishlist is some secret injection of some kind. There are many solutions out there for dynamically injecting secrets into environment variables into pods at runtime, but thats not really what I want. I don’t want the workloads (agents) to have direct access to my secrets.

What I really want, is a network-level secret injection. That does exist, you can do it with LiteLLM or OpenRouter - but those are really AI workload specific. You could do something like Cloudflare workers.

Of course I could roll my own middleware, but frtunately, the answer already exists within the ecosystem I’ve deployed. Its Envoy!

For HTTP traffic, it’s all going through my Envoy proxy anyway. That enables me to filter on HTTP headers, does my TLS inspection, but also enables me to inject credentials into web requests via the HTTPRouteFilter 🔥

There’s a bit of nuance here. This is really credential injection rather than secret injection. The later is just too variable and is application specific, whereas credential injection for specific services via headers is much more sensible. For secret injection, you’d probably need to implement the environment variable setting. If you have a requirement for a network-level injection for secrets, then that sounds like it would be specific to your use case. Either way, if you want network-level injection of headers or modification of web traffic, the approach implemented in straightjacket can work.

Companion app

In building this harness out, it became pretty obvious pretty quick that I was going to need a companion app to help actually use this beast.

Remembering commands and policies across cilium, tetragon, envoy settings, gvisor, kyverno. Domain name lists, fingerprinting, SBOM, TLS inpsection, network packet captures… it’s all just way too much to remember - especially for a less-than-part-time proof of concept side project. Maybe one day, I’ll develop an interface to manage all the policies via a unified engine.

The reality is that this kind of project requires full-time engineers to build/manage/maintain, and I just don’t have those resources.

The straightjacket app ships with a local companion app which tries to simplify administration of the application.

CLI Tool

In addition to the companion app, I realized that I probably needed a companion CLI tool to help interact with the cluster and simplify management. This project really has grown arms and legs!

Without it, to interact with the controller to pause a gVisor sandbox, i’d need to run something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Explicit workload-cluster credentials.
export CONTEXT="your-workload-context"
export KUBECONFIG_FILE="/absolute/path/to/workload.kubeconfig"
export NS="workloads"
export POD="my-app"

k() {
  mise -C runtime-telemetry -E live exec -- kubectl \
    --context "$CONTEXT" --kubeconfig "$KUBECONFIG_FILE" "$@"
}

# Bind the request to this Pod instance, not a future replacement.
POD_UID="$(k -n "$NS" get pod "$POD" -o jsonpath='{.metadata.uid}')"
OP="pause-$(date -u +%Y%m%d%H%M%S)"

REQUEST="$(cat <<EOF
apiVersion: sandbox.straightjacket.dev/v1alpha1
kind: SandboxOperation
metadata:
  name: $OP
  namespace: $NS
spec:
  podName: $POD
  podUID: $POD_UID
  action: pause
EOF
)"

# Validate, then submit.
printf '%s\n' "$REQUEST" | k create --dry-run=server -f - &&
printf '%s\n' "$REQUEST" | k create -f -

# Inspect completion and the controller's runtime observation.
k -n "$NS" get sandboxoperation "$OP" --watch
# Ctrl+C stops the watch, not the pause.
k -n "$NS" get sandboxoperation "$OP" -o yaml

So the repo ships with the staightjacket CLI tool, so instead, i can just run:

1
2
3
4
5
sj -- pause workloads/my-app --cluster lab
sj -- resume workloads/my-app --cluster lab
sj -- snapshot workloads/my-app --cluster lab
sj -- trace syscalls workloads/my-app --cluster lab
sj -- logs workloads/my-app --cluster lab

Data Processing

A significant component of this idea is the real-time data processing, which is technically independent of the harness. I havent invested the time on this component of the idea yet, and I have respect for data engineering to understand this also dosent have a simple answer. I am making my way through designing data-intensive applications v2, but I don’t have the time to focus my attention on it properly.

I do have something, but will conceed that the majority of the design for data consumption and thetechnical execution has been heavily delegated to my AI agent.

Together we’ve come up with using Apache Flink and message bus architecture for controllers and consumers, reading from a message bus.

The challenge now becomes trying to figure out the early signals for malicious activity, and stop the activity before it can be completed.

The runsc pause/resume controller is rapid, so is there any problem in starting/stopping a container hundreds of times in a few minutes? It would allow me to offload some of this difficult decision making to a small language model or LLM as a judge, who’s only purpose is to process this kind of activity.

Next Steps

Setting up all these sensors is the core prerequisite that this project satisifies. The data processing is by far the least immature component. This could take some serious engineering to get working at the scale I imagine. It could also pave the way for graph-based reasoning and heuristic data, and turn into a observability/security monitoring challenge (as I’ve blogged about in the past).

Testing & Demonstration

The real-time data processing and feedback into a unified policy engine is a bit of a pipe dream at the moment (the detective 🔄 preventative control loop). However, I’m really happy with the core sandbox harness, and the data collection framework I have in place.

I’ve come up with 14 demonstrations which I think give a good indication of the current capability. Click the links to be taken straight to the relevant section of the demonstration.

Some of the demo’s I’ve had to hold off for now (strikethrough), as I’ve just ran out of time and need to get this post out! I will come back and edit the post when I have some coverage.

General Architecture Overview
Demo Timestamp: 00:00-08:28

Companion Application(s) Overview
Demo Timestamp: 08:28-14:27

Containers

Scratch Container (#1)
Deploying a scratch container, running just a binary which queries the internet. The demonstration shows that basic container primitves are captured, and the agnostic harness implements strong prevenatative and detective controls.
Demo Timestamp: 14:27-19:27

Ubuntu Container (#2)
A container with a few more capabilities, such as file read/writes, standard operating system tools (wget, curl, nc).
Demo Timestamp: 19:27-24:08

Agents

Single Coding Agent - Codex (#3)
A container running codex. As per my example earlier in the blog, only api.openai.com is allowed, and I get my agent to browse the web. This section demonstrates the network inspection guaranteeing detection controls even when upstream providers act as a proxy.
Demo Timestamp: 28:48-37:14

Multi Agent Swarm (~10x Agents) (#4)
Here I deploy an agent swarm (not artex!). This section demonstrates multi-pod and agent communication, whilst still restricting outbound internet access and tool call. It also highlights the volume of signal this system can gather (depending on your policies!) and why the data processing engine is such a core component. This demonstration also includes an auto-scaling event, showing that this system will automatically grow with demand.
Demo Timestamp: 37:14-40:50

Network Tests

Domain and IP Allowlisting (#5)
Deny-by-default policy, with specific domains and IPs allowed.
Demo Timestamp: 20:09-22:25

IDMS Monitoring & IPv4 decimal representations (#6)
As this is running on AKS, can we access the metadata service? This shows what a workload trying to connect to http://169.254.169.254/metadata/instance?api-version=2025-04-07 flags up, including hackery like using decimal notation via browser.

DNS Exfiltration (#7)
Demonstration of trying to exfiltratino data via DNS from within the sandbox. First directly, secondly via DNS service hosted within the workload to demonstrate that no matter the configuration, the harness see’s all!

Port scanning (#8)
Demonstration showing what a nc port scan looks like, and the type of signal this system can gather.
Demo Timestamp: 22:22-23:13

ICMP Testing (#9)
Its not just limited to TCP/IP, this shows how traceroute and ping manifest within the harness and the comprehensive capability it has for network signal gathering.

TLS Inspection (#10)
Demonstrate the automatic certificate bundle loading into a container, and functional TLS inpsection for an allowed downstream target.
Cert bundling -> 14:27-17:36
Cleaner TLS inspection demo -> 33:01

Forensics

Workload snapshot retrieval and processing (#11)
Lets assume we think the agent has done something sus, this demonstration shows the gvisor snapshot functionality across an entire workload, and how the files are stored in a storage account, and how we could pull the files down and peak inside them. This demonstrations shows taking a look at memory capture and snapshotting. Disk and process dumping isnt native gVisor snapshot functionality, but I’ve got some ideas about how to add thatcoming soon.
Demo Timestamp: 26:36-28:48

Next generation PCAP capture (#12)
Cilium can give us native PCAP capture. The system doesnt (yet) support a continuous capture, but the capability it there! This demonstration dumps node network traffic, and we take a peek at it via wireshark, and use copilot cli to process the file (my PCAP inspection days are long gone!)

Workload Control

Pause and resume workloads (#13)
Probably my favourite feature of the whole project. If I get a whiff of something unsavoury, the ability to pause an entire workload to buy some breathing room for further processing. If everything looks legit, we can continue as if nothing ever happened!
Demo Timestamp: 24:08-26:36

Credential Injection

Authenticate to OpenAI via header injection (#14)
Add OpenAI inference credentials via the Envoy credential injection capability, and demonstrate that the workload cannot view the credentials, but is functional.
Demo Timestamp: 34:24-37:02

Closing

I’ve tried to keep this blog post brief, and let the demonstration and code do the talking.

This project is super interesting to me, and I think I’m going to continue improving it for a while. I don’t think this problem, or the core primitives are going away any time soon, and I expect this area to gain even more traction in the coming years months.

I make no claim that this is perfect, please feel free to contribute, spin your own thing. If you’re working on anything similar, or have any comments on the concepts, please get in touch!

This post is licensed under CC BY 4.0 by the author.