VIRT-SANDBOX.C(1)

πŸ“¦
version 0.8.0 Β· 2 versions
, in fedora 43

πŸ’– VIRT-SANDBOX.C(1) β€” Virtualization Support πŸ’–

okay bestie, so this is virt-sandbox.c(1) from the virtualization support section, and it's genuinely one of the most underrated little tools out there. it's basically a tiny virtual machine you can yeet a command into so it can't touch anything it's not supposed to. let's get into it 🫢


✨ NAME ✨

virt-sandbox β€” run cmd under a virtual machine sandbox


🌸 SYNOPSIS 🌸

virt-sandbox [OPTIONS...] COMMAND

virt-sandbox [OPTIONS...] -- COMMAND [CMDARG1 [CMDARG2 [...]]]

πŸ¦‹ DESCRIPTION πŸ¦‹

So like, virt-sandbox runs the "cmd" application inside a tightly confined virtual machine. and when we say tightly confined we mean it. the default sandbox domain only lets applications do exactly this: read and write stdin, stdout, and any other file descriptors that get handed to it. that's it. it is not allowed to open any other files. no cap. it's giving minimal privileges, main character energy, iconic. πŸ‘‘


πŸ’… OPTIONS πŸ’…

  • -c URI, --connect=URI β€” sets the libvirt connection URI. if you don't specify one, it defaults to qemu:///session. alternatively you can set the "LIBVIRT_DEFAULT_URI" environment variable, or set a default URI in the config file "/etc/libvirt/libvirt.conf". heads up: currently only the QEMU and LXC drivers are supported.
  • -n NAME, --name=NAME β€” sets the unique name for the sandbox. it defaults to sandbox, but bestie you will need to change this if you're running more than one sandbox at the same time. this name is what gets used as the name of the libvirt virtual machine or container.
  • -r DIR, --root DIR β€” use DIR as the root directory of the sandbox, instead of inheriting the host's root filesystem.
NB. "DIR" must contain a matching install of the libvirt-sandbox package. this restriction may be lifted in a future version. so like, don't come for me if it's strict rn πŸ™ˆ
  • --env key=value β€” sets up a custom environment variable on a running sandbox.
  • --disk TYPE:TAGNAME=SOURCE,format=FORMAT β€” sets up a disk inside the sandbox by using SOURCE with a symlink named as TAGNAME and type TYPE and format FORMAT. example: file:cache=/var/lib/sandbox/demo/tmp.qcow2,format=qcow2. Format is an optional parameter.
    • TYPE β€” Type parameter can be set to "file".
    • TAGNAME β€” TAGNAME will be created under /dev/disk/by-tag/TAGNAME. it will be linked to the device under /dev.
    • SOURCE β€” Source parameter needs to point a file which must be a one of the valid domain disk formats supported by qemu.
    • FORMAT β€” Format parameter must be set to the same disk format as the file passed on source parameter. this parameter is optional and the format can be guessed from the image extension.
  • -m TYPE:DST=SRC, --mount TYPE:DST=SRC β€” sets up a mount inside the sandbox at DST backed by SRC. the meaning of SRC depends on the value of "TYPE" you specify:
    • host-bind β€” if TYPE is host-bind, then SRC is interpreted as the path to a directory on the host filesystem. if "SRC" is the empty string, then a temporary (empty) directory is created on the host before starting the sandbox and deleted afterwards. the "--include" option is useful for populating these temporary directories with copies of host files.
    • host-image β€” if TYPE is host-image, then SRC is interpreted as the path to a disk image file on the host filesystem. the image should be formatted with a filesystem that can be auto-detected by the sandbox, such as ext3, ext4, etc. the disk image itself should be a raw file, not qcow2 or any other special format.
    • guest-bind β€” if TYPE is guest-bind, then SRC is interpreted as the path to another directory in the container filesystem.
    • ram β€” if TYPE is ram, then SRC is interpreted as specifying the size of the RAM disk in bytes. the suffix K, KiB, M, MiB, G, GiB can used to alter the units from bytes to a coarser level.

some examples ✨

 -m host-bind:/tmp=/var/lib/sandbox/demo/tmp
 -m host-image:/=/var/lib/sandbox/demo.img
 -m guest-bind:/home=/tmp/home
 -m ram:/tmp=500M
  • -I HOST-PATH, --includefile=HOST-PATH β€” copy all files listed in inputfile into the appropriate temporary sandbox directories.
  • -N NETWORK-OPTIONS, --network NETWORK-OPTIONS β€” add a network interface to the sandbox. NETWORK-OPTIONS is a set of key=val pairs, separated by commas. the following options are valid:
    • dhcp β€” configure the network interface using dhcp. this key takes no value. no other keys may be specified. eg
 -N dhcp,source=default
 --network dhcp,source=lan

where 'source' is the name of any libvirt virtual network.

  • source=NETWORK β€” set the name of the network to connect the interface to. "NETWORK" is the name of any libvirt virtual network. see also virsh net-list.
  • mac=NN:NN:NN:NN:NN:NN β€” set the MAC address of the network interface, where each NN is a pair of hex digits.
  • address=IP-ADDRESS/PREFIX%BROADCAST β€” configure the network interface with the static IPv4 or IPv6 address IP-ADDRESS. the PREFIX value is the length of the network prefix in IP-ADDRESS. the optional BROADCAST parameter specifies the broadcast address. some examples
 address=192.168.122.1/24
 address=192.168.122.1/24%192.168.122.255
 address=2001:212::204:2/64
  • route=IP-NETWORK/PREFIX%GATEWAY β€” configure the network interface with the static IPv4 or IPv6 route IP-NETWORK. the PREFIX value is the length of the network prefix in IP-NETWORK. the GATEWAY parameter specifies the address of the gateway for the route. some examples
 route=192.168.122.255/24%192.168.1.1
  • -s SECURITY-OPTIONS, --security=SECURITY-OPTIONS β€” use alternative security options. SECURITY-OPTIONS is a set of key=val pairs, separated by commas. the following options are valid for SELinux:
    • dynamic β€” dynamically allocate an SELinux label, using the default base context. the default base context is system_u:system_r:svirt_lxc_net_t:s0 for LXC, system_u:system_r:svirt_t:s0 for KVM, system_u:system_r:svirt_tcg_t:s0 for QEMU.
    • dynamic,label=USER:ROLE:TYPE:LEVEL β€” dynamically allocate an SELinux label, using the base context USER:ROLE:TYPE:LEVEL, instead of the default base context.
    • static,label=USER:ROLE:TYPE:LEVEL β€” to set a completely static label. for example, static,label=system_u:system_r:svirt_t:s0:c412,c355
    • inherit β€” inherit the context from the process that is executing virt-sandbox.
  • --kernver=VERSION β€” specify the kernel version to run for machine based sandboxes. if omitted, defaults to match the current running host version.
  • --kernpath=FILE-PATH β€” specify the path to the kernel binary. if omitted, defaults to "/boot/vmlinuz-$KERNEL-VERSION".
  • --kmodpath=DIR-PATH β€” specify the path to the kernel module base directory. if omitted, defaults to "/lib/modules". the suffix "$KERNEL-VERSION/kernel" will be appended to this path to locate the modules.
  • -p, --privileged β€” retain root privileges inside the sandbox, rather than dropping privileges to match the current user identity.
  • -S USER, --switchto=USER β€” switch to the given user inside the sandbox and setup $HOME accordingly.
  • -l, --shell β€” launch an interactive shell on a secondary console device.
  • -V, --version β€” display the version number and exit.
  • -v, --verbose β€” display verbose progress information.
  • -d, --debug β€” display debugging information.
  • -h, --help β€” display help information.

🌈 EXAMPLES 🌈

Run an interactive shell under LXC, replace $HOME with the contents of $HOME/scratch

  # mkdir $HOME/scratch
  # echo "hello" > $HOME/scratch/foo
  # echo "sandbox" > $HOME/scratch/bar
  # virt-sandbox -c lxc:/// -m host-bind:$HOME=$HOME/scratch -i $HOME/scratch/foo -i $HOME/scratch/bar /bin/sh

Convert an OGG file to WAV inside QEMU

  # virt-sandbox -c qemu:///session  -- /usr/bin/oggdec -Q -o - - < somefile.ogg > somefile.wav

πŸ‘€ SEE ALSO πŸ‘€

sandbox(8), virsh(1)


🫢 AUTHORS 🫢

Daniel P. Berrange <dan@berrange.com>


Copyright (C) 2011 Daniel P. Berrange <dan@berrange.com> Copyright (C) 2011-2012 Red Hat, Inc.


⭐ LICENSE ⭐

virt-sandbox is distributed under the terms of the GNU LGPL v2+. this is free software; see the source for copying conditions. there is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. (periodt.)


and that's the whole page bestie πŸ’– this was libvirt-sandbox-0.8.0, dated 2025-07-24, and yes it's still out here being iconic. go forth and sandbox responsibly, ily πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from