home /all posts/ here

AOW-02 Sandboxes in kagent 1.0

December 2, 2026 • 4 minutes read • agentic-engineering advent-of-word-2026

As I shared in the last post, I've been exploring ways to deploy sandboxed agents in Kubernetes. kagent is a popular framework to do this and version 1.0 provides a way to sandbox agents using agent-substrate. TIL that kagent also supports the second approach (separate agent and sandbox workspace).

In 1.0, kagent has a Sandbox entity which essentially sandboxes anything it is asked to. It's a generic "sandbox". It generalises the concept of sandboxing in agent-substrate, in fact it's the same logic that runs under the hood in substrate.

To make use of a sandbox you define a SandboxTemplate which defines how sandboxes should be created. An agent gets access to tools that can create new sandboxes and interact with them - this happens via an MCP server.

apiVersion: api.kagent.dev/v1alpha3
kind: SandboxTemplate
metadata:
name: my-sandbox
namespace: kagent
spec:
substrate:
workerPoolRef:
name: default
snapshotPolicy:
location: s3://my-kagent-substrate-snapshots/
workload:
image: my-tools-image

The key thing here is workload.image: it specifies a custom "tools" image that will be applied to the sandbox. This is useful to provide custom capabilities/files to the sandbox if needed, which usually is. Consider you are building a simple coding agent that takes in a bug report, implements a solution in a repository and verifies it. We'd have to provide the agent with the repository files and tools like e.g. Node.js to work with. You could technically decide to do this in a session, but it is much faster to start in a warm sandbox. Using workload.image, you can pass in an image that has Node.js and git installed.

An example tools image:

# Tools image for a kagent SandboxTemplate.
# kagent injects its own guest program, so this image only carries tools.
FROM node:24-alpine
RUN apk add --no-cache git bash

# Bake in the CLI and a pre-initialised project
RUN npm install -g typescript
WORKDIR /opt/workspace-seed
RUN npm init -y && npm install --save-dev vite

The agent would look like:

apiVersion: api.kagent.dev/v1alpha3
kind: Agent
metadata:
name: my-sandbox-agent
namespace: kagent
spec:
harnessRef:
name: default
template:
inline:
description: Fixes bugs
modelConfig:
name: agentgateway-powerful
systemPrompt: |
You are a bug fixer. Every session should create a new sandbox. Use the tools provided by kagent-api.

tools:
- mcp:
server:
kind: RemoteMCPServer
name: kagent-api
tools:
- create_sandbox
- get_sandbox
- resume_sandbox
- write_sandbox_file
- read_sandbox_file
- start_sandbox_process
- get_sandbox_process
- read_sandbox_outputs
- kill_sandbox_process

Once applied, the agent appears in the UI and can be used. The agent loop runs separate from the workspace, which runs in a sandbox.

kagent-sandbox.png

Substrate does some optimisations to create sandboxes fast - it has a concept of golden snapshot which is a snapshot of a sandbox created from a template. This is used to create new sandboxes quickly on demand, via the create_sandbox tool. Additionally, the sandboxes are durable, i.e. their state is check-pointed to S3 at crucial events. Every sandbox has a /data directory which gets saved to the snapshot. Anyone using the sandboxes works with /data/workspace by default. Checkpointing happens when a sandbox worker is suspended, i.e. when the work happening on it pauses for some time or other work needs space.


Using SandboxTemplate and Agent you can pretty much implement the decoupled architecture for deploying cloud agents. Then the sandbox worker pool can be scaled independent of agents while keeping the workers running the agent loop lean.

Useful links:

Related posts


Subscribe to get my latest posts by email.

    I won't send you spam. Unsubscribe at any time.