How to use virtual machines

A workshop runs in an LXD container unless its definition says otherwise. Workshop can instead run it as a full virtual machine with a kernel of its own, which draws a harder boundary than a container can. Reach for a virtual machine when you want that boundary, or when the workshop itself has to run LXD containers and virtual machines. The boundary stops at the kernel: the project directory, including its .git directory, is still mounted read-write, and outbound network access is still open, so a virtual machine doesn’t protect the project from a coding agent that works in it.

Note

A virtual machine consumes more memory and disk than a container, and it does not support every feature a container does; the Limitations section lists what it skips.

Prerequisites

Before starting, ensure you have these requirements satisfied:

  • A Workshop installation that supports the runtime key.

  • A host with hardware virtualization available.

  • A workshop you have not launched yet. The runtime is fixed when a workshop is launched, so an already running container workshop cannot be converted.

Check that Workshop lists the runtimes it supports:

$ workshop init --help

  ...
  The supported runtimes are lxd-container (the default) and lxd-vm.
  ...

Create a virtual machine workshop

Generate a definition with the --runtime flag:

$ workshop init <NAME> --runtime lxd-vm

  "<NAME>" workshop definition created at /home/user/my-project/.workshop/<NAME>.yaml

The generated definition carries the runtime:

.workshop/<NAME>.yaml
name: <NAME>
base: ubuntu@24.04
runtime: lxd-vm

Add the same key by hand to a definition you already wrote. runtime accepts lxd-container and lxd-vm; omitting it selects lxd-container.

Launch and verify

Launch the workshop the same way as any other:

$ workshop launch <NAME>

  "<NAME>" launched

A virtual machine boots from a different base image than a container, so the first launch on a given base downloads that image.

Confirm what you got:

$ workshop info <NAME>

  name:      <NAME>
  base:      ubuntu@24.04
  project:   ~/my-project
  hostname:  <NAME>.my-project.wp
  status:    ready
  runtime:   lxd-vm
  cpus:      2
  memory:    4GiB
  disk:      10GiB
  notes:     --

The runtime line is the confirmation: a container workshop reports runtime: lxd-container instead.

Manage the workshop

Stopping, starting, and removing a virtual machine workshop use the same commands as a container:

$ workshop stop <NAME>

  "<NAME>" stopped
$ workshop start <NAME>

  "<NAME>" started
$ workshop remove <NAME>

  "<NAME>" removed

A running virtual machine workshop also starts again on its own after the host reboots, and it is reachable over SSH by hostname, in both cases exactly as a container workshop is. See Cross-workshop networking for reaching a workshop by hostname.

Limitations

Virtual machine workshops are not at parity with containers. The differences below change what you can do with one.

The runtime is fixed at launch

Editing runtime in the definition of a launched workshop and refreshing it fails:

$ workshop refresh <NAME>

  error: cannot refresh "<NAME>": cannot refresh "<NAME>": runtime changed from "lxd-vm" to "lxd-container"

Remove the workshop and launch it again to change the runtime.

Most interfaces are unsupported

Currently, virtual machine workshops only support the mount and secret interfaces. Other interfaces will not be auto-connected and cannot be connected manually. The mount interface can only be connected when the workshop is running.

Virtual machine workshops can still install SDKs that contain unsupported plugs and slots, but these plugs and slots will not be listed in workshop connections.

Removing stopped workshops

Disconnecting a mount interface plug from a slot with workshop-source requires the workshop to be running. This can prevent removing a stopped workshop. Either start the workshop before removing it, or see How to purge malfunctioning workshops. A future Workshop release will remove this limitation.

Sessions end when the host suspends

If the host suspends for 35 seconds or longer, workshop shell sessions exit abruptly when the host resumes. The command inside the workshop may still be running. A future LXD release will fix this issue.

Virtual hardware is restrictive

Virtual machines are modeled on physical hardware and have hard limits for:

  • The number of processors.

  • Total system memory.

  • The root disk size.

These quantities can be adjusted in the workshop definition file. Changes will be applied on the next workshop refresh.

Interfaces can be connected and disconnected while the workshop is running, but much like devices plugged into a physical machine, there’s a limit to the total number of interface connections.

The simplest way to avoid these limits is to disconnect unused interfaces. In some cases, Workshop uses the number of SDKs to predict hardware requirements; adding an SDK without many plugs or slots can help to compensate for one with several active connections.

See also

Explanation:

How-to guides:

Reference: