K8EK8E
Home
  • What is K8E
  • Getting Started
  • Sandbox Runtime Setup
  • Sandbox CLI
  • Sandbox Examples
  • Sandbox with E2B SDK
  • DeepSeek Harness
  • Architecture
  • Components
  • Advanced Installation
  • K8E vs Alternatives
  • Contributing
Changelog
  • English
  • 简体中文
GitHub
Home
  • What is K8E
  • Getting Started
  • Sandbox Runtime Setup
  • Sandbox CLI
  • Sandbox Examples
  • Sandbox with E2B SDK
  • DeepSeek Harness
  • Architecture
  • Components
  • Advanced Installation
  • K8E vs Alternatives
  • Contributing
Changelog
  • English
  • 简体中文
GitHub
  • Guide

    • What is K8E?
    • Getting Started
    • Sandbox Runtime Setup
    • Sandbox CLI
    • Sandbox Examples — Driven by Your AI Agent
    • Sandbox with the Official E2B SDK
    • DeepSeek Harness + k8e-sandbox — Step-by-Step
    • Architecture
    • Components
    • Advanced Installation
    • K8E vs Other Sandbox Platforms
    • Contributing

Sandbox Examples — Driven by Your AI Agent

Everything in this guide is driven from your agent harness (pi, Claude Code, or Codex) using the /k8e-sandbox skill. You describe the goal in plain language; the skill runs k8e-sandbox-cli for you inside an isolated sandbox pod. You never have to type the CLI commands yourself — but each example shows what the skill actually does behind the scenes, so you always know what's happening.

Prerequisites

  1. Complete Step 3 of Getting Started: download the CLI, connect, and install the skill into your agent harness.
  2. Invoke the skill in your harness:
    • pi: /skill:k8e-sandbox <goal> (or just ask naturally)
    • Claude Code: /k8e-sandbox <goal>
    • Codex: $k8e-sandbox <goal> (or pick from /skills)

Every time the skill runs it follows the same loop: pre-flight (status check) → plan → execute in the sandbox → report the real output. Work through the levels below in order — each one builds on the previous.

💡 Not using an agent harness? K8E also speaks the E2B protocol natively — the official e2b SDKs (Python/JS) work unmodified. See Sandbox with the Official E2B SDK for SDK-driven examples (create, exec, files, watch, pause/resume) that need no skill at all.


Level 1 — Hello World: a marquee animation

You ask your agent:

"Use Python to write a marquee animation and run it in the sandbox"

The skill does (pre-flight + execute):

k8e-sandbox-cli status                              # pre-flight: gateway available?
k8e-sandbox-cli run --lang python --raw <<'EOF' |
import sys, time
msg = "K8E SANDBOX "
for i in range(40):
    sys.stdout.write("\r" + msg[i % len(msg):] + msg[:i % len(msg)])
    sys.stdout.flush()
    time.sleep(0.1)
print()
EOF
  sed -u -n 's/^data: {"stdout":"\(.*\)"}$/\1/p' | base64 -d

You see the marquee scrolling live in your terminal — the carriage returns move the cursor back, so the text slides instead of piling up.

Why the pipe?

--raw strips the CLI's JSON wrapper, but what comes out is the server's SSE framing, not plain text:

data: {"stdout":"S1QgU0FOXkFCWCA="}
data: {"exit":0}

Each frame's payload is base64 so that newlines and ANSI escapes inside the output can never break the frame boundaries. The sed + base64 -d pair above turns the stream back into the bytes the program actually printed. Without --raw you get the same text, but only once the command finishes:

k8e-sandbox-cli run --lang python <<'EOF' | jq -r .stdout
print("hello from the sandbox")
EOF

Newer k8e-sandbox-cli versions print the plain text directly — the decoding moved into the CLI (k8e PR #671), so run --raw no longer needs the pipe. Check which one you have:

k8e-sandbox-cli run --raw "echo hi" | head -1

If it prints hi, drop the pipe. If it prints data: {"stdout":"…"}, keep it. The two are mutually exclusive — the pipe filters out plain text entirely.

No host-side Python was involved — it all ran inside the isolated pod.

Try it: ask for a bash one-liner (echo 'hello from sandbox') or a TypeScript snippet (--lang ts) the same way. The skill picks the language for you.


Level 2 — Data script: files & dependencies

You ask your agent:

"In the sandbox, install pandas and run a script that prints its version"

The skill does (create session → write file → install → run → read back):

SID=$(k8e-sandbox-cli create | jq -r .session_id)   # explicit session, reused below
k8e-sandbox-cli write $SID /workspace/script.py <<'PYEOF'
import pandas as pd
print("pandas", pd.__version__)
PYEOF
k8e-sandbox-cli run "pip install pandas" --session-id $SID
k8e-sandbox-cli run "python3 /workspace/script.py" --session-id $SID
k8e-sandbox-cli read $SID /workspace/script.py
k8e-sandbox-cli list $SID                            # see what changed in /workspace
k8e-sandbox-cli destroy $SID                         # clean up when done

You see pandas 2.x.y plus the file listing. Package installs work out of the box — the default egress allowlist includes pypi.org, registry.npmjs.org, and github.com.

Try it: ask the agent to analyze a CSV you describe ("load this CSV, print the row count and the mean of each numeric column"). The skill writes the script, runs it, and shows you the numbers — all inside the sandbox.


Level 3 — Clone a repository and build it

You ask your agent:

"Clone https://github.com/user/repo.git into a sandbox and build it"

The skill does (clone at session creation, then build by language):

SID=$(k8e-sandbox-cli create --git-repo https://github.com/user/repo.git --git-ref main | jq -r .session_id)
k8e-sandbox-cli run "ls -la /workspace/repo" --session-id $SID
k8e-sandbox-cli run "cd /workspace/repo && go build ./..." --session-id $SID          # Go
# or: cd /workspace/repo && npm install && npm run build                              # Node
# or: cd /workspace/repo && pip install -r requirements.txt                           # Python

You see the build logs streamed back, and the skill reports pass/fail + exit codes. You can iterate ("fix the failing test and re-run") and the skill keeps using the same sandbox, so state persists between turns.

Try it: ask for a specific runtime — "clone it and build with Go" or "run its test suite" — the skill maps your request to the right commands.


Level 4 — Build & verify a Vue website

You ask your agent:

"Create a Vite + Vue website in the sandbox, build it, and verify it serves"

The skill does (scaffold → install → build → verify → local preview):

SID=$(k8e-sandbox-cli create | jq -r .session_id)
k8e-sandbox-cli run "npm create vite@latest my-app -- --template vue" --session-id $SID
k8e-sandbox-cli run "cd /workspace/my-app && npm install" --session-id $SID
k8e-sandbox-cli run "cd /workspace/my-app && npm run build" --session-id $SID
k8e-sandbox-cli run "ls -la /workspace/my-app/dist && head -30 /workspace/my-app/dist/index.html" --session-id $SID
k8e-sandbox-cli run "grep -o '<title>[^<]*</title>' /workspace/my-app/dist/index.html" --session-id $SID
k8e-sandbox-cli run "cd /workspace/my-app && (npm run dev >/dev/null 2>&1 &) && sleep 3 && curl -s http://localhost:5173/ | head -20" --session-id $SID
k8e-sandbox-cli destroy $SID

You see the built dist/ listing, the <title> tag, and the dev server responding on :5173 — verified with curl inside the sandbox. Your Vue site was scaffolded, built, and smoke-tested without touching your host.

Open it in your browser (KIP-24): expose the dev server through the k8e API Gateway and open the returned URL:

k8e-sandbox-cli expose 5173 --session-id $SID
# -> {"url":"http://<gateway>/k8e/expose/<sid>/5173/",...}

Then open that URL from any host that can reach the gateway. Stop serving with k8e-sandbox-cli unexpose 5173 --session-id $SID. See Sandbox CLI → Expose a Service.


What you learned

LevelYou askedThe skill ranYou got
1run a marquee in the sandboxrun --lang python --rawlive animated output
2install pandas + run a scriptcreate → write → run → read/list → destroyversion + file listing
3clone + build a repocreate --git-repo → language buildbuild logs + exit codes
4scaffold + verify a Vue sitenpm create → install → build → curlbuilt site + dev-server smoke test

The pattern is always the same: you describe the goal, the /k8e-sandbox skill turns it into k8e-sandbox-cli calls, and everything runs in an isolated pod. For the raw command reference, see Sandbox CLI.

Last Updated: 10/24/26, 4:45 AM
Prev
Sandbox CLI
Next
Sandbox with the Official E2B SDK