SLM Code Interpreter
Lightweight local Python Code Interpreter agent with automated self-correcting feedback loops and timeout constraints inside sandboxed environments.
02 / Standalone OS Harness Installers, CLI & Python SDK
In SLMAgents 2.0, SLM Code Interpreter executes inside the 10-Plane Pure-CPU Agent Harness (slm_harness). Download a self-extracting Individual Agent + Harness OS Installer for macOS, Windows, or Linux (bundling slm_code_interpreter + slm_harness + the ./slm CLI), install the full 26-agent desktop suite, or install via Python pip:
1. Individual SLM Code Interpreter + 10-Plane Harness Installers (All OSes)
slm_code_interpreter + slm_harness + ./slm CLIslm_code_interpreter + slm_harnessslm_code_interpreter + slm_harness + ./slm CLI2. Full 26-Agent Studio & Desktop OS Installers
3. 10-Plane Harness CLI (./slm) & Python pip Installation
# Option A: Install via PyPI or editable source with the 10-Plane Harness $ pip install slm-code-interpreter $ pip install -e ./slm_harness -e ./slm_code_interpreter # Option B: Run directly through the Unified 10-Plane Pure-CPU Harness CLI (./slm) $ ./slm ask "Write and execute Python code to compute the first 15 Fibonacci numbers and their mean" $ ./slm chat # Interactive Rich TUI with 18 slash commands (/trace, /models, /arena, /undo) $ ./slm serve # 100% Offline Web AI Studio + OpenAI /v1 API at http://127.0.0.1:7860
03 / 10-Plane Pure-CPU Harness Integration (slm_harness)
Rather than executing as an isolated prompt wrapper, SLM Code Interpreter is natively orchestrated by the SLMAgents 2.0 10-Plane Pure-CPU Harness (via slm_harness.runtime.legacy_bridge and CascadeRouter). Every call benefits from hybrid llama.cpp GGUF (Q4_K_M) + Quantized INT4/INT8 CPU execution, watermarked LRU memory governance, grammar-constrained decoding, and deterministic verification at $0 API cost:
| Harness Plane | Subsystem | How It Powers SLM Code Interpreter on Pure CPU |
|---|---|---|
| Plane 6 | CascadeRouter (<35ms) |
Stage 2 (Python AST / Code Execution Signature) & Stage 3 (Embedding Margin) |
| Plane 2 & 5 | MemoryArena & Hybrid CPU Runtime |
Specialist Role: coding (Qwen2.5-Coder-1.5B INT4 / Qwen3-4B GGUF Q4_K_M). Managed inside Watermark LRU MemoryArena (lite 2.6 GB / balanced 4.7 GB / power 8.2 GB) with zero-copy session sharing and automatic OOM tier step-down (8B -> 4B -> 3B -> 0.8B). |
| Plane 7 & 8 | Deterministic Verifier & Governance | Plane 7 Python AST Syntax & Subprocess Sandbox Verifier with 2-Turn Automated Traceback Self-Repair |
| Plane 1, 3 & 4 | Kernel, Artifact Scratchpad & 4-Tier Memory | SQLite WAL CheckpointStore (/fork, /rewind, /undo), content-addressed artifact://<sha12> handles to prevent prompt bloat, and hybrid SQLite FTS5 BM25 + HNSW vector memory. |
04 / Source Checkout (Git Sparse-Checkout)
Clone this agent alongside the 10-Plane Pure-CPU Harness (slm_harness) from the monorepo using Git sparse-checkout — no need to download all 26 agents:
Option 1 — Sparse Checkout with 10-Plane Harness (Recommended)
# 1. Create and enter a new directory $ mkdir slm_code_interpreter_workspace && cd slm_code_interpreter_workspace # 2. Initialise empty git repo and add remote $ git init $ git remote add origin https://github.com/t00114218-stack/SLMAgents.git # 3. Enable sparse-checkout for both slm_harness and slm_code_interpreter $ git sparse-checkout init --cone $ git sparse-checkout set slm_harness slm_code_interpreter # 4. Pull the 10-Plane Harness and agent source $ git pull origin main
Option 2 — Full Repository Clone
$ git clone https://github.com/t00114218-stack/SLMAgents.git $ cd SLMAgents $ ./slm doctor
Note: After checkout, install the harness and agent in editable mode with pip install -e ./slm_harness -e ./slm_code_interpreter or download the pre-packaged OS Harness Installer above.
05 / Configuration & API Reference
Constructor Parameters
| Parameter | Type / Default | Description |
|---|---|---|
| model_path | str | None | Explicit path to GGUF (Q4_K_M) or quantized ONNX model directory. Defaults to zero-copy sharing via the 10-Plane Harness MemoryArena. |
| cache_dir | str | None | HF model directory path. Also settable via SLM_CODE_INTERPRETER_CACHE_DIR. |
| n_ctx | int | 2048 | Context window size in tokens. Also settable via SLM_CODE_INTERPRETER_N_CTX. |
| n_threads | int | 4 | CPU threads for the 10-Plane Pure-CPU Harness (auto-tuned to physical P-cores). Also settable via SLM_CODE_INTERPRETER_N_THREADS. |
| system_prompt | str | None | Optional custom system prompt instructions overriding the default template. |
| user_input | str | None | Optional additional user-supplied target parameters or variables. |
run() Parameters
| Parameter | Type / Default | Description |
|---|---|---|
| instruction | str | Required. Natural language description of what you want the script to calculate or print. |
| max_retries | int | 3 | Number of turns the self-correction engine is allowed to attempt standard traceback fixes. |
| stream | bool | False | If True, enables token streaming of the model's explanation and thinking process. Returns a Python generator. |
| system_prompt | str | None | Optional custom system prompt instructions overriding the default template. |
| user_input | str | None | Optional additional user-supplied target parameters or variables. |
from slm_code_interpreter.code_interpreter import SLMCodeInterpreter
interpreter = SLMCodeInterpreter()
query = (
"Load CSV text: date,department,revenue. Group by department, "
"extract quarter, sum revenue, filter >= 40000 and print table."
)
result = interpreter.run(query)
print(result["success"])
print(result["stdout"]) # Prints markdown summary table of results
Agentic Self-Correction Loop
Although code writing can be difficult for small models, making it agentic through a feedback loop (writing code → executing locally → catching exceptions → feeding errors back to the model) allows a local model to achieve high execution accuracy.
If run_code_safely captures a traceback or runtime stderr, it wraps it inside the conversation history and prompts the model with instructions to correct it:
"The code execution failed with return code 1. Error logs: NameError: name 'x' is not defined. Correct your code errors and return the complete updated code inside
python."
Sandbox Subprocess Limits
The code interpreter sandboxes execution inside restricted, resource-constrained subprocesses. It enforces standard execution limits:
- Timeout Safety: Terminates infinite loops automatically after 10.0 seconds to prevent thread locking.
- Process Isolation: Cleans up temporary files instantly after the execution returns.
🔌 Visual Studio Code Integration
You can run the Code Interpreter as a background service and trigger local executions directly from your VS Code editor workspace.
Step 1: Start the Background Daemon Server
Execute the local HTTP server in your terminal:
python -m slm_code_interpreter.server
The daemon activates a local REST API listening on port 8085.
Step 2: Run the VS Code Extension Blueprint
A pre-configured extension is provided under the vscode-extension/ directory:
- Open the extension directory in VS Code.
- Press
F5to launch a debug instance of the editor. - Highlight any instructions or python code blocks inside your editor workspace, right-click, and select: "SLM Code Interpreter: Execute Selected Prompt / Code".
- Monitor execution progress and trace outputs inside the VS Code Output Channel under "SLM Code Interpreter".