Commands · reference

vmlab clipboard

3 min read · 2026-09-02 · vmlab 0.9

vmlab clipboard reads or writes a guest's clipboard over the guest agent channel. No guest network is involved, so it works on a machine with no NIC at all.

sh
vmlab clipboard <COMMAND>
SubcommandMeaning
getWrite the guest clipboard to stdout, with no trailing newline added.
setSet the guest clipboard from TEXT, or from stdin when TEXT is omitted.
-h, --helpPrint help.

Both subcommands take a machine reference of the form [lab/]machine. A bare name is resolved against the lab in the current directory, and the lab daemon is started if none is running. The qualified form addresses a lab that is already running from any directory and never starts one. The machine must be running with an agent that advertises the clipboard feature; see vmlab machine capabilities. The agent advertises it only where it can reach a display server, so on a headless guest both subcommands refuse with the guest agent has no clipboard.

A Windows agent always advertises clipboard, because someone can log on at any time. The Windows clipboard belongs to an interactive session, so on a guest at the lock screen with nobody logged on both subcommands refuse at once:

text
winsrv: no one is logged on to the desktop; the Windows clipboard belongs to an interactive session (it works once a user logs on)

Log on at the console (vmlab console) and run the command again. A locked session still counts as logged on, so the clipboard keeps working after the screen locks.

vmlab clipboard get

sh
vmlab clipboard get [OPTIONS] <MACHINE>
OptionMeaning
<MACHINE>The machine, as [lab/]name.
--jsonEmit the raw JSON string instead of the bare text.
-h, --helpPrint help.

The guest's clipboard text is written to stdout byte for byte. No newline is appended, so what you pipe on is exactly what the guest held. With --json the text is printed as one JSON string literal instead. The agent is given 10 seconds to answer.

vmlab clipboard set

sh
vmlab clipboard set [OPTIONS] <MACHINE> [TEXT]
OptionMeaning
<MACHINE>The machine, as [lab/]name.
[TEXT]The text to copy. Omit it to read stdin.
--jsonEmit the raw JSON reply instead of a confirmation.
-h, --helpPrint help.

With a TEXT argument that text becomes the guest's clipboard. Without one, stdin is read to end of file and passed through verbatim, trailing newline included, so vmlab clipboard get a | vmlab clipboard set b round-trips exactly. Use echo -n when you do not want the newline echo adds. On success the verb prints `copied N bytes to "<machine>" clipboard; with --json it prints the daemon's reply, which is true`.

The confirmation is printed only after the agent reports that the text is on the guest clipboard; the agent is given 10 seconds to report. An agent that predates the clipboard_reply feature sends no such report, so against one the confirmation means only that the request was sent.

Examples

Move a password from one guest to another without typing it:

sh
vmlab clipboard get dc01 | vmlab clipboard set client01

Paste a host file's content into a guest:

sh
vmlab clipboard set client01 < notes.txt

Read a guest's clipboard into a shell variable:

sh
token=$(vmlab clipboard get buildbox)

Exit status

Exit status is 0 when the clipboard was read or written. Exit 4 (not_found) means the lab declares no machine by that name. Exit 6 (unsupported) means the agent lacks the clipboard feature. A machine that is not running, an agent that is not answering, a guest the agent cannot reach the clipboard of (nobody logged on to a Windows desktop), and a request that times out all exit 1 (failed). A qualified reference to a lab that is not running exits 1. A usage error exits 2.