kosa8 / Guides / Secure sandbox for AI agents
Guide · Isolation · Last checked: November 2026
Secure sandbox for AI agents: what to require
A secure sandbox for an AI agent is one where every control that matters sits outside the agent's reach. Require a kernel boundary the agent does not share with your host (a microVM, or at minimum a user-space kernel), a network that is closed by default and opened per host by rules enforced outside the sandbox, no real credentials inside, hard limits on resources and time, a clean state for every task, a person in the loop for risky actions, and a record of every action written by something the agent cannot edit. A sandbox that only isolates the file system is a convenience, not a security control.
01Why an agent needs more than a container
An AI agent is a program that decides its own next step, using input written by people you have never met. A README, an issue, a web page or a tool description can carry instructions, and the model may follow them. That is prompt injection, and it is first on the OWASP Top 10 for LLM Applications. Nobody has a reliable way to filter it out, so the practical question is not whether the agent can be steered but what it can reach when it is.
OWASP names that second problem Excessive Agency: an agent with more tools, permissions and network than its task needs. A sandbox is the tool that sets those limits. To be a security control rather than a tidy workspace, each limit has to be enforced by something the agent cannot change, even as root inside its own machine.
Three things decide most outcomes: what kernel the agent's code talks to, where its traffic can go, and what secrets it can read. The rest of this page turns those into requirements you can test.
02The requirements, with a test for each
Ask for each of these, and check it yourself rather than reading it off a feature list.
A kernel boundary. The agent's system calls go to a guest kernel behind hardware virtualization, not to your host kernel. Test: run
uname -rinside and outside; a microVM reports its own kernel.One folder in, nothing else. No home directory, no SSH agent, no cloud credentials file, never the container runtime's socket. Test: list
~/.ssh,~/.awsand/var/runfrom inside.Default-deny egress, enforced outside. Every connection and DNS query is refused unless its destination is on a list you wrote, and the rule lives on the host or in the virtual network path. Test: as root inside, flush the firewall and try
curl https://example.comand a raw IP address. Both should still fail. See default-deny egress for AI agents.No real secrets inside. The sandbox holds placeholders; a broker outside adds the real credential only on requests to that credential's own host. Test: print the environment inside. See keep API keys out of AI agents.
Metadata and private ranges blocked. Link-local addresses such as
169.254.169.254, loopback and your internal networks are unreachable unless listed. Test: request the cloud metadata address from inside.Hard limits. CPU, memory, disk, process count and a wall-clock timeout, all failing closed. Test: run a fork bomb and a memory hog in a throwaway sandbox and confirm the host stays responsive.
Known state per task. Each task starts from a fresh sandbox or a clean snapshot, and nothing carries across users or tenants. Test: leave a file and a background process behind, start the next task, look for both.
Human approval for risky actions. Force pushes, deploys, deletes and payments wait for a named person, and the approval covers that exact call. See requiring human approval.
An audit trail outside the sandbox. Commands, network attempts (allowed and refused), approvals and policy changes, written by the host and tamper-evident. See tamper-evident audit trails for AI agents.
Policy the agent cannot change. Network rules, tool rules and approvers are set before the sandbox boots and cannot be edited from inside it.
A way to stop everything. A kill switch that pauses or freezes every sandbox at once, usable during an incident.
03Isolation technologies compared
The boundary is the first requirement and the one that is hardest to add later. This table compares technologies, not products.
| Technology | Kernel the agent talks to | Escape needs | Where egress rules can live | Good fit |
|---|---|---|---|---|
| Process sandbox (seccomp, Landlock, macOS Seatbelt) | Host kernel, behind a filter | A bug in an allowed system call or the filter | Host firewall or proxy settings the process honours | Narrowing a trusted tool on a laptop |
| Container (runc) | Host kernel | One kernel or runtime bug | Host firewall, network namespace, sidecar proxy | Reviewed code on a patched host |
| Container under gVisor | A user-space kernel, then a narrow set of host calls | Bugs in gVisor and then the host | Host firewall, gVisor network stack | Smaller host-kernel surface without VMs |
| WebAssembly runtime | The runtime, through granted interfaces | A runtime bug | Only the sockets you grant | Code you can compile to Wasm |
| MicroVM (Firecracker, Cloud Hypervisor, Kata Containers) | Its own guest kernel, behind hardware virtualization | A guest kernel bug and then a hypervisor or device bug | The host side of the virtual network, outside the guest | Unreviewed agent code that needs a full Linux |
| Full VM | Its own guest kernel, full device model | As a microVM, with a larger device surface | Host or hypervisor network | Long-lived, manually run environments |
Agents usually want a full Linux userland: a shell, package managers, compilers and browsers. That leaves gVisor and microVMs as the realistic choices for unreviewed work. MicroVM vs container isolation for LLM code execution goes deeper on that choice, with escape paths and start-up costs.
04Which approach fits
- A coding agent on your own laptop, on your own repository. The agent's built-in sandbox mode or a process sandbox is a sensible floor. Move to a microVM once the agent runs unattended, reads untrusted issues or web pages, or holds keys that matter. The local sandbox guide covers the setup.
- A product that runs code for your users. One microVM (or gVisor sandbox) per user session, fresh or restored per task, default-deny egress and no shared state across tenants. How to safely run untrusted LLM-generated code covers this case.
- Agents with access to production systems or customer data. Everything above plus a credential broker, approvals on writes and an audit trail forwarded to your SIEM. This is the zero trust model applied to agents.
- Regulated or classified work. Sandboxes on hardware you control, possibly with no network at all. See on-premise and air-gapped agent sandboxes and the regulated industries checklist.
05Common gaps
- A firewall inside the sandbox. Root inside can remove it; the rule must live outside.
- An HTTP proxy with no packet filter underneath. Programs that ignore proxy settings, or dial an IP address, go straight past it.
- Passing the parent environment in, with every API key it holds.
- One long-lived sandbox shared by several users or tasks.
- Logs written inside the sandbox, where the agent can edit or delete them.
- Treating a prompt filter as the boundary. Filters lower the odds; only the sandbox sets a limit.
06One way to do it: kosa8
kosa8 is Zero Trust cybersecurity infrastructure for AI agents, and it covers the requirements above in one tool. Each agent runs in its own microVM with its own kernel: Apple's Virtualization framework on a Mac, Cloud Hypervisor on KVM on x86-64 Linux. The agent's machine sees one folder. Network egress goes to an allow-list enforced on the host, outside the microVM, and DNS answers only listed names. API keys stay outside the sandbox: an egress broker on the host adds the real key on requests to that key's own host, and the sandbox holds a placeholder. Risky steps can wait for one or two named approvers, and every action goes to a hash-chained, signed audit log. A checkpoint captures memory, processes and disk, and a rewind puts the sandbox back.
kosa8 sandbox create agent --egress-allow api.anthropic.com kosa8 agent run -w ~/code/api claude kosa8 audit verify
It runs on Apple silicon Macs, x86-64 Linux and Windows 11 through WSL2 (preview), on kosa8 Cloud, on your own servers joined to kosa8 Cloud, or air-gapped. On hosted kosa8 Cloud, each sandbox is still its own microVM, but the audit log, evidence export and signed policy are features of the software on your own machines and hosts; hosted Cloud sandboxes do not expose them yet.
kosa8 limits what a hijacked agent can reach; it does not detect prompt injection. SOC 2 Type II is in progress; there is no SOC 2 report and no external penetration test yet.
To try a kosa8 sandbox without installing anything or making an account, kosa8.com/try runs code in a fresh sandbox with no outbound network: 15 minutes of run time free per 24 hours, each run up to 60 s.
Try free with no account. Starter is free with no card; plans from $29 a month.
07Questions
What makes a sandbox secure enough for an AI agent?
Every control sits outside the agent's reach: a kernel boundary it does not share with the host, default-deny network rules enforced on the host, no real credentials inside, hard resource limits, a clean state per task, approvals for risky actions and an audit trail the agent cannot edit.
Is a Docker container a secure sandbox for an AI agent?
A hardened container is a reasonable floor for reviewed code on a patched host. It shares the host kernel, so one kernel or runtime bug can become a host escape. For agents that run code nobody reviewed, use gVisor or a microVM.
Does a sandbox stop prompt injection?
No. A sandbox does not stop the model being steered. It limits what a steered agent can reach: which files, which hosts, which credentials and which actions go ahead without a person.
Why must network rules be enforced outside the sandbox?
Anything inside can be changed by root inside. A firewall in the guest can be flushed and proxy settings can be ignored, so the rule has to live on the host or in the virtual network path, where the agent has no access.
Should each agent task get a new sandbox?
Yes, or a sandbox restored from a clean snapshot. Reusing one environment lets one task's files, packages or processes affect the next, and across users it leaks data.
08Sources and further reading
Last checked: November 2026 · Updated 2026-11-29