Kagex/Guides
Python · SSEAgent Integrations · 4 min read

Stream AI Sandbox Commands from Python over Unix Socket & SSE

Zero external packages needed: stream live stdout/stderr over /v1/executions/{id}/stream, search huge build logs via /grep, and clean up sandboxes reliably in Python.

Example
docs/examples/python-harness/harness.py
Dependencies
Python 3 stdlib only (no pip required)
Log search
GET /v1/executions/{id}/grep
Run the built-in Python stdlib SSE harness
# macOS / Linux Unix socket:
python3 docs/examples/python-harness/harness.py ./test/node-app

# Windows / Docker TCP + Bearer token:
SANDBOXD_URL=http://127.0.0.1:17070 SANDBOXD_TOKEN="$(sandboxd token)" \
  python3 docs/examples/python-harness/harness.py

Key Engineering Points · 11-Tool MCP Server & One-Command IDE Wiring

All 10 key points →
  • 1sandbox-mcp implements JSON-RPC 2.0 over stdio and bridges seamlessly into sandboxd over Unix domain sockets or loopback TCP.
  • 2sandboxctl mcp install antigravity creates .agents/plugins/kagex/ (or ~/.gemini/config/plugins/kagex/ with --global) containing plugin.json, mcp_config.json, rules/AGENTS.md, and skills/sandbox/SKILL.md.
  • 3sandboxctl mcp install cursor configures .cursor/mcp.json (or ~/.cursor/mcp.json) alongside always-applied .cursor/rules/sandbox.mdc.
  • 4sandboxctl mcp install claude writes .claude/skills/sandbox/SKILL.md and registers the MCP server via claude mcp add with --scope project or --scope user.
  • 5sandboxctl mcp install codex backs up ~/.codex/config.toml to config.toml.bak, appends [mcp_servers.sandbox] (30s startup, 900s tool timeout), and updates AGENTS.md.
  • 6Eleven specialized tools cover full dev workflows: sandbox_exec, sandbox_read_file, sandbox_write_file, sandbox_diff, sandbox_apply, sandbox_pull, sandbox_snapshot, sandbox_network, sandbox_port, sandbox_status, and sandbox_destroy.

Real-Time Streaming & Structured Output Search

Pass wait=false when calling /v1/sandboxes/{id}/exec to get an immediate exec_id, then consume chunked stdout/stderr/exit frames via Server-Sent Events or query large logs with regex grep without blowing agent context windows.

Drop-In Replacement for Cloud Evaluators

Swap cloud code-interpreter API calls in SWE-bench or Python agent loops with HTTP calls to localhost sandboxd for instant zero-cost iteration.

Inspect this architecture live in 3D

Step through MCP ingress, Ghost Secrets, CoW blades, and run sandboxctl commands interactively in your browser.

Frequently Asked Questions

No. Python talks solely to the sandboxd HTTP socket using OS peer credentials on Unix or a local Bearer token on TCP.