beetlebug

Agents

Give a coding agent tools that use few tokens, a debugger that it can call, and a sandbox for its programs. Or build an agent loop that reads untrusted text and can only do what its tools allow.

A terminal with one ztcl code command: a search for thread::create, the definition of a proc, and four lines of a file

The picture shows ztcl code on this repository. One command runs three tools, and the output of each tool is short.

Tools for a coding agent

ztcl code runs the tools of ztcl::code from a shell: search, outline, show, and edit. An agent sends one script with several commands and reads one short answer.

ztcl code 'grep thread::create examples/usecases -n 5
def run_plugin examples/usecases
show examples/usecases/untrusted-code/host.tcl 51-54'
ztcl code replace host.tcl 'set level interp' 'set level process'
ztcl code 'run -ask "Which tests failed?" {zig build test}'

ztcl code turns on exec and the files of the host, so a script has the full power of the user. Use it for your own tree.

A debugger over MCP

ztcl debug --mcp serves tools over the Model Context Protocol. An agent runs a script with probes, reads the report of an error, and evaluates code in the interpreter of the last run:

{"mcpServers": {"ztcl": {"command": "ztcl", "args": ["debug", "--mcp"]}}}

The runner options after --mcp set the capabilities and the limits of each run.

Claude Code in a harness

ztcl code claude runs Claude Code in an isolated thread. A panel next to it shows the tokens, the tasks, the changed files, and each tool call. At the level process, Claude Code and its programs can read the files of the user and change only the project and a short list of folders. At the level vm, they run in a Linux guest that has only the project and the folders that you share.

Agent loops in a sandbox

ztcl::agent runs an agent loop in an isolated thread. A tool is a Tcl command of the host, and the thread has no capability:

package require ztcl::agent
proc draft_reply {text} {save_draft $text; return "draft saved"}
ztcl::agent doc draft_reply "Save a draft reply. It does not send it." text string

set r [ztcl::agent run -api openai -endpoint http://127.0.0.1:8090/v1/chat/completions \
    -system "You sort email. Draft a short reply, then give the result." \
    -prompt "Sort this email." -data [list email $text] -tools {draft_reply} \
    -result {category {enum spam work personal} summary string} -meter agents]

A prompt injection in the email can make the model call a tool. The model can only call draft_reply, so the most that a hijacked agent can do is save a draft. -compute and -meter limit and count the work of the loop.

What is in ztcl

ztcl code, ztcl debug --mcp, the harness, and ztcl::agent are part of ztcl. The level vm of the harness needs Linux with KVM.

More