VIRT-SANDBOX.C(1)
π 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 toqemu:///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 tosandbox, 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β useDIRas the root directory of the sandbox, instead of inheriting the host's root filesystem.
NB."DIR"must contain a matching install of thelibvirt-sandboxpackage. 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 usingSOURCEwith a symlink named asTAGNAMEand typeTYPEand formatFORMAT. 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βTAGNAMEwill 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 atDSTbacked bySRC. the meaning ofSRCdepends on the value of"TYPE"you specify:host-bindβ if TYPE ishost-bind, thenSRCis 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 ishost-image, thenSRCis 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 asext3,ext4, etc. the disk image itself should be a raw file, notqcow2or any other special format.guest-bindβ if TYPE isguest-bind, thenSRCis interpreted as the path to another directory in the container filesystem.ramβ if TYPE isram, thenSRCis interpreted as specifying the size of the RAM disk in bytes. the suffixK,KiB,M,MiB,G,GiBcan 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-OPTIONSis a set ofkey=valpairs, 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 alsovirsh net-list.mac=NN:NN:NN:NN:NN:NNβ set the MAC address of the network interface, where eachNNis a pair of hex digits.address=IP-ADDRESS/PREFIX%BROADCASTβ configure the network interface with the static IPv4 or IPv6 addressIP-ADDRESS. thePREFIXvalue is the length of the network prefix inIP-ADDRESS. the optionalBROADCASTparameter 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 routeIP-NETWORK. thePREFIXvalue is the length of the network prefix inIP-NETWORK. theGATEWAYparameter 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-OPTIONSis a set ofkey=valpairs, 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 issystem_u:system_r:svirt_lxc_net_t:s0for LXC,system_u:system_r:svirt_t:s0for KVM,system_u:system_r:svirt_tcg_t:s0for QEMU.dynamic,label=USER:ROLE:TYPE:LEVELβ dynamically allocate an SELinux label, using the base contextUSER: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,c355inheritβ inherit the context from the process that is executingvirt-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$HOMEaccordingly.-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 π
π«Ά AUTHORS π«Ά
Daniel P. Berrange <dan@berrange.com>
π COPYRIGHT π
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
- fedora 43: libvirt-sandbox 0.8.0-19.fc43 Β· LicenseRef-Callaway-LGPLv2+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms