Set up a sandbox template
Create a sandbox template, then start a Sandbox from it and run a command.
About this tutorial
A Sandbox is an isolated scratch environment that a person, a script, or an agent creates to run commands. A sandbox template says what every Sandbox of one kind starts with: the container image that holds its programs, and the worker pool that runs it.
In this tutorial, you create a template for Python, start a Sandbox from it, and run a command in it. The kagent UI has no page for sandbox templates, so you work from the command line. For what a Sandbox is and what isolates it, see Sandboxes and Core concepts.

Time: about 10 minutes.
Before you begin
Install kagent, and make sure that the
kagentCLI andjqare on your path.Set the sandbox guest image. kagent runs its own guest program in every Sandbox, and the chart does not ship a default image for it, so a template does not become ready until you set one.
cat > sandbox-values.yaml <<'EOF' config: sandboxes: guestImage: ghcr.io/kagent-dev/kagent/sandbox-guest@sha256:16e84a2285119ce02cc6ba45ea7f68181eb1527335de85477614fb9a6b5ecf03 EOFApply the file to your kagent release. The commands read the installed chart version, so that the upgrade keeps that version and the release’s other values.
export KAGENT_CHART_VERSION=$(helm list -n kagent -o json \ | jq -er '.[] | select(.name == "kagent") | .chart | ltrimstr("kagent-")') helm upgrade kagent \ oci://ghcr.io/kagent-dev/kagent/helm/kagent \ --namespace kagent --version "$KAGENT_CHART_VERSION" \ --reuse-values -f sandbox-values.yaml --wait
Choose an image
The image holds every program that the Sandbox can run. A Sandbox has no network access unless you grant it, so a command cannot install a missing package later.
Pick an image that already contains every program that your commands need. This tutorial uses
python:3.13-slim.Read the image’s digest. kagent accepts only an image that is pinned to a digest.
docker buildx imagetools inspect python:3.13-slim --format '{{json .Manifest.Digest}}'
Create the template
Apply the template. It uses the
kagent-defaultworker pool and the snapshot location that the installation sets up.kubectl apply -f - <<EOF apiVersion: api.kagent.dev/v1alpha3 kind: SandboxTemplate metadata: name: python namespace: kagent spec: workload: image: docker.io/library/python:3.13-slim@sha256:e48f59cdba69a3cbd9ed2cf0f348d90d45a8d350d98134cf1070bc106ee9ed90 env: - name: LANG value: C.UTF-8 substrate: workerPoolRef: name: kagent-default snapshotPolicy: location: s3://ate-snapshots/kagent/ EOFWait until the template is ready. kagent builds a snapshot of the template first, which can take a minute the first time that a Worker pulls the image.
kubectl wait sandboxtemplate/python -n kagent --for=condition=Ready --timeout=5mIf the command times out, read the reason.
kubectl get sandboxtemplate python -n kagent \ -o jsonpath='{range .status.conditions[?(@.type=="Ready")]}{.status} {.reason} {.message}{end}'The reason
PreparationFailedusually means that the guest image from Before you begin is not set.List the templates that you can create a Sandbox from.
kagent sandbox templatesExample output:
NAMESPACE NAME IMAGE kagent python docker.io/library/python:3.13-slim@sha256:e48f59cdba69a3cbd9ed2cf0f348d90d45a8d350d98134cf1070bc106ee9ed90
Verify the template
Create a Sandbox from the template, and save its ID. The request ID makes the command safe to retry.
export SANDBOX_ID=$(kagent sandbox create python --request-id "cli-$(uuidgen)" -o json | jq -r .id) echo $SANDBOX_IDRun a command in the Sandbox.
kagent sandbox exec $SANDBOX_ID -- python --versionExample output:
Process proc-2c32646d3e4cac9f0763a1da in sandbox 01a209a5-684a-7106-85ca-8851f2059dd6: started (stdout offset 0, stderr offset 0) Python 3.13.18 Process proc-2c32646d3e4cac9f0763a1da: PROCESS_STATE_EXITED, exit_code=0
What you built
A sandbox template for Python, and a Sandbox started from it. Along the way, you used these features:
| Feature | What you did | Read more |
|---|---|---|
| Sandbox templates | Pinned an image to a digest, and chose the worker pool and snapshot location | Set up sandbox templates |
| The sandbox CLI | Created a Sandbox and ran a command in it | Run commands with the CLI |
Clean up
Delete the Sandbox.
kagent sandbox delete $SANDBOX_IDOptional: Delete the template. Build a sandbox coding agent applies the same
pythontemplate, so keep it if you go on to that guide.kubectl delete sandboxtemplate python -n kagent