kosa8 / Cybersecurity / Tool execution sandbox

Architecture · Tool execution · Updated 2026-11-29

Secure sandbox infrastructure for AI agent tool execution

Secure tool execution means every tool call that touches code, files, a shell, a browser or the network runs inside isolated compute the agent cannot escape, with the rules decided outside it. In practice that is five layers: a sandbox with its own kernel per task or session, a network that is closed by default and enforced on the host, credentials added outside the sandbox, approval gates for consequential actions, and an audit record the agent cannot edit. Design it on the assumption that some agent will be steered by a prompt injection, and keep that agent's reach small.

01What counts as tool execution

A model only produces text. Everything an agent does that has an effect goes through tools: a code interpreter, a shell, file reads and writes, a headless browser, MCP servers, HTTP calls to internal and external APIs, and database queries. Each one runs code on some machine with some permissions. The sandbox decides which machine and how much permission.

Tools fall into two groups, and most production agents have both:

  • Compute tools (interpreters, shells, builds, browsers, third-party MCP servers) run code you did not write. They need an isolation boundary.
  • Action tools (send an email, merge a pull request, issue a refund) call a real system with real authority. They need policy and approval more than compute isolation.

02A reference architecture

Six layers, from the model outwards:

  1. Agent runtime. The loop that calls the model and picks the next tool. Treat everything it emits as untrusted input to the layers below.
  2. Tool gateway. Receives each call, checks it against policy (allow, deny, or ask a person), pins tool definitions so a server cannot quietly change what a tool does, and routes the call.
  3. Sandbox compute. One isolated machine per task, session or tenant, where code runs: its own kernel, a resource quota and one working folder.
  4. Egress guard. Every packet leaving the sandbox passes a policy point on the host. Deny by default, allow named hosts, and answer DNS for those names only.
  5. Credential broker. Holds the real keys outside the sandbox and adds them to outbound requests for the right host only.
  6. Audit and evidence. An append-only record of calls, decisions, approvals and network attempts, written outside the sandbox and forwarded off the machine.

Layers 2, 4, 5 and 6 sit outside the sandbox, and that is the point. Root inside the sandbox must not be able to change its own rules, read the real keys or rewrite its history. This is the zero trust model of NIST SP 800-207 (no implicit trust, least privilege per request, decisions made where the subject cannot change them) applied to a workload that takes instructions from whatever it reads. Zero trust sandboxes for AI agents maps each tenet to a control.

03Requirements, and how to test each one

Test every requirement as root inside the sandbox, the position a hijacked agent would be in.

RequirementWhy it mattersHow to check it
Own kernel per sandboxA shared-kernel bug reaches every tenant on the hostCompare uname -r inside and on the host; confirm the runtime is a VM or a user-space kernel
Network denied by default, enforced on the hostExfiltration needs a route outFlush the firewall rules inside, then reach an unlisted host; it must still fail
DNS limited to allowed namesDNS is a data channel and a discovery toolResolve an unlisted name from inside; expect no answer
Metadata endpoints blockedCloud metadata hands out credentialsRequest 169.254.169.254 from inside; expect failure
No real secrets insideAnything readable can be printed and sentDump the environment and search the filesystem; find no live keys
Hard quotasRunaway loops and fork bombsRun a memory and process bomb; the sandbox stops, the host does not
Tenant separation in the APIA guessed ID must not reach another tenant's sandboxCall another tenant's sandbox with your token; expect a refusal
Clean state per taskLeftovers leak data and skew resultsWrite a file in one task, start the next; the file must be gone
Approval for consequential actionsSome actions cannot be undoneTrigger a gated tool; it must wait for a named person
Tamper-evident auditYou must be able to say what the agent didVerify the log, edit one entry, verify again; it must fail

04Isolation choices for tool execution

TechnologyBoundaryFits tool execution whenWatch out for
Container (runc)Shared host kernel; namespaces, cgroups, seccompThe tool runs your own reviewed codeOne kernel or runtime bug can reach the host
gVisorUser-space kernel in front of the host kernelYou want a smaller kernel surface on existing container toolingNot every system call is supported; syscall-heavy work is slower
WebAssemblyRuntime with only the interfaces you grantSmall, pure functions you can compile to WasmMost agent tools expect a full Linux with pip and npm
MicroVMOwn guest kernel behind hardware virtualizationThe tool runs code nobody reviewed, installs packages or runs unattendedMemory per instance; you need KVM or a hypervisor framework
Full VMOwn guest kernel, full device modelLong-lived, rarely recreated environmentsSlow to create; heavy to run per task

For general tool execution the realistic choice is gVisor or a microVM. The trade-offs are set out in MicroVM vs container isolation for LLM code execution.

05Session models and latency

ModelLifetimeUse forWatch out for
Per callOne tool callStateless code interpreters, untrusted snippetsStart-up cost on every call; no state between steps
Per sessionOne task or conversationCoding agents, data analysis, browser agentsClean-up at the end; idle cost
Per tenantLong-lived, one customerPersistent workspacesDrift; never share across tenants
ForkedLive copies of one running sandboxParallel attempts, evals, RL rolloutsClone safety: duplicated IDs, random seeds and network identity

Latency decides which model is practical, and two techniques make per-session and even per-call virtual machines affordable. A warm pool keeps pre-booted sandboxes paused, so a create is a resume. A memory snapshot lets a prepared environment restore instead of booting. In kosa8's own benchmark on one server (3 Nov 2026), a create from the warm pool took 1.9 ms at the median and a restore from snapshot 74 ms. Under load the host's CPU and memory became the limit, so the pool has to grow and shrink with demand. The benchmark study has the hardware, method and raw figures.

06MCP servers and third-party tools

An MCP server is third-party code that your agent calls with your data. Run each one in its own sandbox with its own allow-list, so a compromised server reaches only the hosts it needs and none of your files. Pin each server's tool definitions when you approve it, and hold any later change for review: a server that changes a tool's description after approval, sometimes called a rug pull, is a documented attack on agents. Give each server only the credential for its own API, through the broker. The MCP specification's security best practices cover the protocol side.

07Human approval and a stop switch

Isolation limits what a hijacked agent can reach. Approval limits what it can do with the access it legitimately has. Gate the actions that are irreversible or costly: deleting data, moving money, sending messages outside the company, changing access and deploying. An approval should name a person, be recorded and be usable once. For the highest-risk actions, require two people.

Keep one control that stops everything at once: pause every sandbox, refuse new work and suspend keys. You will want it the first time an agent loops on an expensive call at night.

08Build it or adopt it

You can assemble this yourself. On Linux with KVM, Firecracker, Cloud Hypervisor or Kata Containers give you microVMs, and gVisor gives you a user-space kernel for containers. What these leave to you is everything around the VM: networking and filtering, snapshot management, clone safety (Firecracker's documentation lists the duplicated identifiers, random state and network configuration to handle when one snapshot is restored into many VMs), credential brokering, approvals, a multi-tenant API and logging. Teams with platform engineers to own that stack do build it. Others adopt a finished layer. Either way, run the requirements table above against it before an agent does.

09One way to do it: kosa8

kosa8 is Zero Trust cybersecurity infrastructure for AI agents, built as this layer. Each agent runs in its own microVM with its own kernel. Network egress goes to an allow-list enforced on the host, outside the microVM. Secrets stay outside the sandbox, and the host adds the real key on requests to that key's own host. Risky steps can wait for a person, with two-person approval where policy requires it. Third-party MCP servers can each run in their own sandbox behind one policy. Every action goes to a hash-chained, signed audit log, and kosa8 audit verify checks it. Checkpoint, rewind and fork work on a running machine.

terminal
kosa8 sandbox create sealed --egress-allow api.anthropic.com
kosa8 checkpoint sealed --label "before the risky bit"
kosa8 rewind sealed
kosa8 audit verify

It runs on your computer (macOS on Apple silicon, Linux x86-64, Windows), on kosa8 Cloud (one region, us-ash1, in Dallas, Texas), on your own servers joined to kosa8 Cloud, or air-gapped. Tools that drive Docker can drive kosa8 by pointing DOCKER_HOST at it; containers started that way share one engine VM, so use kosa8 sandbox when each workload needs a VM of its own. 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.

What kosa8 does not do: it limits what a hijacked agent can reach, but it does not detect or prevent prompt injection. SOC 2 Type II is in progress; there is no SOC 2 report and no external penetration test yet.

Try it free See pricing For security teams

Try free with no account at kosa8.com/try. Starter is free with no card; plans from $29 a month.

10Questions

What is an AI agent tool execution sandbox?

Isolated compute where an agent's tool calls run: code interpreters, shells, browsers and third-party tool servers. A secure one gives each task its own kernel boundary, a network that is closed by default and enforced outside it, no real credentials inside, and an audit record the agent cannot edit.

Does every tool call need its own sandbox?

No. Stateless code execution can use a fresh sandbox per call; coding and analysis agents usually keep one sandbox per task or session and throw it away at the end. What must never happen is one sandbox shared across users or tenants.

Where should the security policy live?

Outside the sandbox: network rules on the host, credentials in a broker, tool rules and approvals in a gateway, and the audit log written by something the agent cannot reach. Anything inside the sandbox can be changed by code running as root there.

How do I sandbox MCP servers?

Run each third-party MCP server in its own sandbox with an allow-list for the hosts it needs, give it only its own API credential through a broker, and pin its tool definitions when you approve it so that later changes need review.

Does sandboxing stop prompt injection?

No. Nothing stops an agent from reading a malicious instruction. Sandboxing, network policy, keeping secrets out and approvals limit what a hijacked agent can do with it.

11Sources and further reading

Updated 2026-11-29