Skip to main content
Run a coding agent interactively on a Vers VM. You’ll create a VM, set up environment variables so your API keys are injected automatically, install Claude Code, SSH in, and let the agent work.

Prerequisites

Step 1: Create the project

Create a new folder for your project if you don’t already have one.
mkdir agent-vm
cd agent-vm
vers init

Step 2: Set environment variables

Use vers env to define environment variables that get injected into every VM you create. This means any tool running inside the VM — including coding agents — can authenticate automatically.
vers env set ANTHROPIC_API_KEY sk-ant-...
Environment variables set with vers env are injected at VM startup. You only need to set them once — they apply to all VMs you create going forward, including branches.
You can verify what’s set:
vers env list

Step 3: Launch the VM

vers run --vm-alias agent-vm
Verify it’s running:
vers status

Step 4: Connect and install Claude Code

vers connect
Inside the VM:
# Set up DNS for outbound internet access
echo 'nameserver 8.8.8.8' > /etc/resolv.conf

# Install Node.js
apt-get update && apt-get install -y ca-certificates curl gnupg
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs

# Install Claude Code
npm install -g @anthropic-ai/claude-code
Verify your API key was injected:
echo $ANTHROPIC_API_KEY
You should see your key printed. If it’s empty, you can set it manually for this session:
export ANTHROPIC_API_KEY=sk-ant-...

Step 5: Start coding with the agent

Create a workspace and give the agent a task:
mkdir -p /root/workspace
cd /root/workspace

claude
This drops you into an interactive Claude Code session. Give it a prompt:
Build a simple todo app with a Node.js Express backend and a clean HTML/CSS frontend. 
The API should support GET /todos, POST /todos, and DELETE /todos/:id. 
Store todos in memory. Serve the frontend from the public/ directory on port 3000.
The agent will create files, install dependencies, and build the app — all inside the VM.

Step 6: Run what the agent built

Once the agent is done, start the app:
cd /root/workspace
npm install
node server.js &
sleep 1
curl -s http://localhost:3000 | head -5
Your app is live at:
https://<vm-id>.vm.vers.sh:3000
Replace <vm-id> with your VM’s ID (shown in vers status).

Step 7: Iterate

You’re still inside the VM with Claude Code available. Keep prompting to make changes:
Add a "completed" checkbox to each todo item that strikes through the text when checked.
The agent edits the files in place. Restart the server to see changes:
pkill node
node server.js &
Refresh your browser.

Step 8: Branch before experiments

Want to try something risky without losing your working state? Exit the VM and branch:
exit
vers branch --alias experiment
vers checkout experiment
vers connect
Now you have a copy of the entire VM — files, installed packages, everything. Try risky changes in the branch. If they don’t work out, switch back:
exit
vers checkout agent-vm
vers connect
Your original state is untouched.

What you learned

  • Setting environment variables with vers env for automatic API key injection
  • Installing and running Claude Code on a Vers VM
  • Interactively building an app with a coding agent over SSH
  • Branching a VM to safely experiment with agent-driven changes

Next steps