> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vers.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Coding agent (SSH)

> Run Claude Code on a Vers VM via SSH

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

* Vers CLI [installed and authenticated](/installation)
* An Anthropic API key from [console.anthropic.com](https://console.anthropic.com)

## Step 1: Create the project

Create a new folder for your project if you don't already have one.

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
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.

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers env set ANTHROPIC_API_KEY sk-ant-...
```

<Info>
  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.
</Info>

You can verify what's set:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers env list
```

## Step 3: Launch the VM

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers run --vm-alias agent-vm
```

Verify it's running:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers status
```

## Step 4: Connect and install Claude Code

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers connect
```

Inside the VM:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
# 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:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
echo $ANTHROPIC_API_KEY
```

You should see your key printed. If it's empty, you can set it manually for this session:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
export ANTHROPIC_API_KEY=sk-ant-...
```

## Step 5: Start coding with the agent

Create a workspace and give the agent a task:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
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:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
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:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
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:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
exit
```

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
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:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
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

* [Agent swarms tutorial](/tutorials/agent-swarms) — orchestrate multiple agents across branched VMs
* [Accessing your instance](/vm-access) — networking, ports, and SSH details
