---
url: /run/vm.md
---
# Running in a microVM

`--backend vm` runs an agent in a Linux virtual machine of its own, which stops when the run ends. The agent sees only its workspace and the files Pandra prepared for it, and it connects only to the destinations you allow. To run an agent in a VM, run it with `--backend vm` in your project's directory:

```sh
pandra run github.com/acme/reviewer@v1.2.0 --backend vm
```

Pandra starts the VM, and the harness's interface opens on your terminal. When you leave it, Pandra lists each destination the agent was refused, with the command that allows it:

```text
✓ Prepared · 0.1s
  Session:  9f2c4e1a7b3d (reviewer)
  VM:       ghcr.io/pandra-io/vm-base, 4 CPUs, 4GiB memory
  Network:  minimal (1 destination)
✓ Started claude-code 2.1.332 (linux-arm64) · 0.3s
...
refused 1 destination:
  github.com
    To allow it for this session:
      pandra policy allow host 9f2c4e1a7b3d4c5e8a6f0b1d2e3f4a5b github.com
To resume this session:
  pandra resume 9f2c4e1a7b3d4c5e8a6f0b1d2e3f4a5b --tui
```

Headless runs, sessions, resumes, and logs work as on the host.

1. You run `pandra run github.com/acme/reviewer@v1.2.0 --backend vm` on your Mac, and Pandra starts a Linux VM for the run.
2. Your workspace, such as `~/src/app`, is shared into the VM at the same path, where the agent and its harness work in it. The workspace and the files Pandra prepared are the only files of your Mac that the VM sees, and what the agent installs stays on the session's own disk in the VM.
3. Every connection the agent makes leaves the VM through Pandra on your Mac.
4. Pandra lets through only the allowed destinations, and adds the credentials it keeps on your Mac.

## Supported platforms

| Platform | `--backend vm` |
|---|---|
| macOS 13 or later on Apple Silicon | Supported |
| macOS on Intel | Not supported |
| Linux | Not supported: agents run on the host only |

Where it is not supported, a VM run fails with `backend_unsupported`, and it never falls back to running as you.

## What the agent sees in the VM

The VM shares these directories of your Mac, each at the same path:

| Directory | Access |
|---|---|
| The run's workspace: the directory you run `pandra` in, or the one `--workspace` names ([workspaces](/run/workspaces.md#workspaces)) | read and write |
| The session's harness home, where the harness keeps its settings and the conversation ([workspaces and sessions](/run/workspaces.md)) | read and write |
| The files Pandra prepared for the run, such as its skills and MCP configuration | read only |
| The harness's installation | read only |

Nothing else of your Mac's files is visible. A workspace that holds Pandra's own data, configuration, or cache directory, such as your home directory, is refused with `vm_workspace_too_broad`: choose a narrower one with `--workspace DIR`.

## Network rules

A run's network rules are a preset plus the destinations you add. To the agent, a name that is not allowed looks like one that does not exist, and a connection that is not allowed is refused.

| Preset | Allows |
|---|---|
| `strict` | Only the model and login endpoints. |
| `minimal`, the default | The model and login endpoints, the package's remote MCP servers, and the registries its servers' runners need, such as `registry.npmjs.org` for `npx`. |
| `balanced` | `minimal`, plus package registries, the base image's mirrors, and code hosts. `--dry-run` lists them. |
| `open` | Every destination except your Mac's loopback and local network. |

To pick a preset and add destinations for one run:

```sh
pandra run . --backend vm --network-preset balanced \
    --allow-host internal.example.com --allow-host '*.example.org'
```

To keep them for an agent, set them in its `policy` table, or in `[policy]` for every agent:

```toml
[agents."ghcr.io/acme/reviewer".policy]
network-preset = "balanced"
allow-hosts = ["internal.example.com", "localhost:5432"]
```

A destination without a port is on port 443, and `pandra config add` adds one to the list ([add to and remove from a list](/configure/agent-settings.md#add-to-and-remove-from-a-list)).

Your Mac's loopback and local network are refused under every preset unless you name them: `--allow-host 10.0.0.5:8080` allows that address, and `--allow-host localhost:5432` makes your Mac's port 5432 reachable from the VM as `host.pandra.internal:5432`.

::: security
An allowed destination can receive anything the agent can read: the workspace and every value that enters the VM. On a connection Pandra does not decrypt, it checks only the server name, so an allowed host's front end can pass it on to another service (domain fronting).
:::

## Allow a destination while the run goes on

To see what a session can reach and what its run has refused so far:

```sh
pandra policy list 9f2c4e1a7b3d
```

To allow a destination at once, for the running VM and for the session's later resumes, and to take it back:

```sh
pandra policy allow host 9f2c4e1a7b3d registry.npmjs.org
pandra policy remove host 9f2c4e1a7b3d registry.npmjs.org
```

`--save` also writes an allowed destination to the agent's `policy` table for its later sessions, and `pandra policy network-preset 9f2c4e1a7b3d balanced` widens the session's preset. Allowing a destination never sends a credential to it.

::: security
Approve destinations yourself. `pandra policy` does not work inside the VM. On your Mac, Pandra refuses `pandra policy allow`, `remove`, and `network-preset` when `PANDRA_RUN_ID` is set, as it is in an agent's run, but an agent on the host runs as you and can unset it.
:::

## Credentials

Pandra keeps these credentials on your Mac, and the agent gets a placeholder in their place:

* a target's credential
* a secret header of a remote MCP server
* your harness login
* a token for named hosts

These enter the VM as they are, where every process in it can read them:

* a value for a local MCP server
* a variable you set in `env` or pass with `--env`, secrets included

The dry run's `Credentials` section says where each credential goes, so check it before a run.

Without a target credential, a VM run uses your harness's login on your Mac. When it has expired, the run fails with `vm_login_expired`: start the harness on your Mac once to renew it. For Claude Code's login, macOS can ask whether `security` may use the keychain item `Claude Code-credentials`; allow it, or the run cannot use the login.

Anthropic's terms may not allow a third-party tool to inject a Claude subscription token; a target with an API key avoids the question ([targets](/configure/targets.md)).

### Tokens for named hosts

A token for named hosts gives tools in the VM a credential for those hosts only. For GitHub:

```toml
[vm.tokens.github]
secret = "gh"                             # a logical secret
hosts = ["github.com", "api.github.com"]
env = "GH_TOKEN"                          # holds the placeholder in the VM
```

The token's hosts become allowed destinations of every VM run, and `[agents."<identity>".vm.tokens.NAME]` sets a token for one agent only. Git uses the token for those hosts, also in a workspace cloned over SSH, and `gh` uses `GH_TOKEN`.

What does not work in a VM: SSH remotes of other hosts, commit signing, and Claude Code's voice mode.

## What the VM does not protect

::: security
The workspace is not protected from the agent. What it writes there can run on your Mac later: a Git hook, an `.envrc`, or a `package.json` script runs when you use git, direnv, or npm there. Every process in the VM, root included, can read a value that enters it. The VM does not protect against flaws in Apple's hypervisor, side channels, or a Mac that is already compromised. On the host backend, an agent's `policy` table has no effect: the agent reaches whatever you can.
:::

## Run an agent in a VM by default

To run one agent in a VM from now on:

```sh
pandra config set --agent ghcr.io/acme/reviewer backend vm
```

A session keeps the backend it started on. `--dry-run` shows what a run would start with: the image, the resources, the network rules, and where each credential goes.

## Environment variables

The VM does not inherit your shell's environment variables. To pass some to one run:

```sh
pandra run . --backend vm --env DATABASE_URL --env LOG_LEVEL=debug
```

`--env NAME` takes the value from your shell, and `--env NAME=VALUE` sets it. `--env` works only with `--backend vm`, since a run on the host inherits your shell's variables. To give an agent a variable in every run, set it in your configuration ([environment variables for agents](/configure/agent-settings.md#environment-variables-for-agents)).

## Resources

A VM gets 4 CPUs and 4 GiB of memory, or less on a smaller Mac. These are limits, not reserved up front: the VM takes memory from your Mac as its programs use it, and keeps what it took until the run ends. To change them for one run:

```sh
pandra run github.com/acme/reviewer@v1.2.0 --backend vm --cpus 2 --memory 8GiB
```

To change them for every VM run, set `cpus` and `memory` in `[vm]` of your [configuration](/configure.md), and for one agent in its `vm` table:

```toml
# ~/.config/pandra/config.toml
[vm]
cpus = 2
memory = "8GiB"

[agents."ghcr.io/acme/reviewer".vm]
memory = "12GiB"
```

## The first run downloads the VM

The first VM run downloads what the VM needs. To download it ahead, such as before going offline:

```sh
pandra sync github.com/acme/reviewer@v1.2.0 --backend vm
```

## Images

The VM boots `ghcr.io/pandra-io/vm-base`, Debian with git, ripgrep, curl, less, Node, uv with Python, the GitHub CLI, and CA certificates. The agent can use `sudo` without a password. What it installs with `apt`, `npm`, or `pip` stays on the session's own disk and is still there when you resume.

To give an agent your project's tools, build an image from the base, such as with this `Dockerfile`:

```dockerfile
FROM ghcr.io/pandra-io/vm-base:2026.11.30
RUN apt-get update \
    && apt-get install -y --no-install-recommends postgresql-client \
    && rm -rf /var/lib/apt/lists/*
```

Push it to a registry, and name it in the `vm` tables:

```toml
[agents."ghcr.io/acme/reviewer".vm]
image = "ghcr.io/acme/dev-image:3"
```

Pandra pulls the image with the credentials `pandra pull` uses. To use an image you built on your Mac without a remote registry, see [Run an agent in a VM with your own image](/examples/vm-image.md). An MCP server distributed as an OCI image cannot run in the VM.

## Publish a port

To reach a server that the agent starts in the VM, publish its port on your Mac's `127.0.0.1`:

```sh
pandra run . --backend vm -p 3000:3000 --prompt "Start the development server."
```

`ports = ["3000:80", "8080"]` in the `vm` tables publishes ports for every run. The server in the VM must listen on all of its addresses (`0.0.0.0`): Vite, which listens only on `127.0.0.1` by default, is reachable once you start it with `--host 0.0.0.0`. A host port that is in use fails the run with `vm_port_in_use`.

## The TUI, editors, and quests

When the harness's interface ends, the harness prints its own resume hint, such as `claude --resume <id>`, which would start the harness on your Mac outside the VM: resume with `pandra resume` instead.

An editor runs an agent in a VM with `--backend vm --acp` ([agents in a microVM](/integrations/editor.md#agents-in-a-microvm)). A quest does not run members in a VM yet ([running a quest](/quests/running.md#what-a-quest-checks-before-it-starts)).

The full details, such as the limits, the wildcard rules, and each error with its fix, are in the [microVM backend reference](/reference/vm.md).
