Skip to main content
Build a pi extension that gives the agent VM-management tools and transparently routes every bash call to a Vers VM — so the agent acts on a remote machine without knowing it.

What you’ll build

  • An extension that registers create_vm, vm_exec, vm_use, vm_local, and an overridden bash tool
  • A transparent routing pattern that generalizes to containers, cloud VMs, SSH hosts, or any remote execution target
  • Time: ~20 minutes — mostly reading, ~80 lines to write

Prerequisites

  • pi coding agent installed
  • Vers account with VERS_API_KEY set in your environment
  • ssh and openssl on your PATH

Step 1: Create the Extension

Create ~/.pi/agent/extensions/my-vers.ts:
Test it loads: run pi -e ~/.pi/agent/extensions/my-vers.ts. Pi should start with no errors.

Step 2: Add VM Creation

Add this inside the myVersExtension function:
Reload pi (/reload in the TUI). Ask the agent to create a VM — it calls your tool and returns a VM ID.

Step 3: Add SSH Execution

Vers VMs use SSH over TLS on port 443. Add the SSH helper and a tool:
Reload. Ask the agent to create a VM then run uname -a on it. You’ll see the VM’s kernel info.
The SSH connection uses openssl s_client as a ProxyCommand to tunnel through TLS on port 443. This is how Vers exposes SSH without opening additional ports.

Step 4: Override bash for Transparent Routing

This is the key pattern. Instead of making the LLM use vm_exec, override the built-in bash so normal commands route to the VM automatically:
Reload. Now:
  1. Ask the agent to create a VM
  2. Ask it to vm_use that VM
  3. Ask it to install Node.js — it runs apt-get install nodejs over SSH without the LLM knowing
The LLM calls bash as usual. Your extension decides where it runs.

Step 5: Add Status on Startup

Show the VM count in the footer when pi starts:
Reload. You’ll see “vers: N VM(s)” in the footer.

The Complete Extension

The full file is ~80 lines of logic. Copy it from the assembled steps above, or see the production version with all four tool overrides (bash, read, edit, write) plus branching, commits, and SCP at hdresearch/pi-v.

Key Patterns

Tool override routing

The LLM doesn’t need to know about routing. It calls the same tools regardless. This pattern works for any remote execution target — containers, cloud VMs, SSH hosts.

API client as closure

The versApi function, activeVmId state, and SSH helpers all live in the extension’s closure. Multiple tools share them. No global state, no classes — just functions and variables scoped to the extension.

Status feedback

ctx.ui.setStatus shows persistent info in the footer. ctx.ui.setWidget shows multi-line info above the editor. Use these to keep the user informed without interrupting the agent.

What’s next

Agent swarms tutorial

Orchestrate many agents across branched VMs — the pattern this extension makes ergonomic.

Full pi-v extension

Production version: read/edit/write overrides, commits, branches, SCP.

API reference

Every endpoint your extension can call.

Architecture

What the extension is actually talking to on the other end of the API.