appjail4win
appjail4win is an AppJail for deploying Windows virtual machines on FreeBSD as vmjails, powered by Overlord and aimed at making setup simple and reproducible instead of requiring you to assemble the virtualization pieces yourself. It works with any Windows version you provide an ISO for, supports unattended installs through autounattend.xml, gives each VM a disposable system disk plus a persistent data disk so user files survive rebuilds, and allows profile-based customization via templates and attributes. It also integrates with Security Groups for network filtering and can be routed through Tor with some network and DNS tweaking.
github.com/AppJail-makejails/appjail4win
How to use this AppJail
General usage
You can obtain the AppJail from the releases section of this repository. However, to go beyond a simple download and be able to update it conveniently from the console, the simplest complementary tool for our purposes is sysutils/bin, a binary manager:
$ doas pkg install -y bin
Install the latest version of this AppJail by running the following command:
$ mkdir -p ~/bin
$ bin install https://github.com/appjail-makejails/appjail4win
Or update it if it is already installed:
$ bin update appjail4win.appjail
Assuming ~/bin is in your PATH, you can run the AppJail simply by using the following command:
$ appjail4win.appjail
Remember that when running an AppJail in portable mode, you must install the key used to verify the binary:
$ cat << "EOF" | doas x11appjail trust [email protected] -
untrusted comment: [email protected] (x11appjail) public key
RWSZbdqRaZVSgICvhui+nrVbXbWw25jyZx/3lhaPzSmVi1Pgvk2DAB1h
EOF
$ x11appjail trusted
KEY COMMENT
37e1a7da5478a29ec3d38ecb14919b107beab67cc0de0b473b5b018f018e1ccb.pub [email protected] (x11appjail) public key
A system-wide installation requires only root access; the key is not necessary. However, it is strongly recommended to verify the binary before installation, making it necessary to install the key anyway.
$ x11appjail verify ~/bin/appjail4win.appjail
Signature Verified
$ doas ~/bin/appjail4win.appjail --install
$ x11appjail run appjail4win
An AppJail creates the jail only if it does not already exist or if the AppJail detects a valid change in its checksum (e.g.: after an update). This means that updates to the OCI image used by the AppJail are only checked at the creation time. If you need to update the OCI image, simply destroy the jail:
$ x11appjail destroy-jail appjail4win
Once you run the AppJail again, the OCI image is pulled again only if it is newer than the one on your system.
D-Bus
To achieve better integration with the desktop environment, the host’s D-Bus is shared via xdg-dbus-proxy(1). By default, the system bus is not shared and the session bus is filtered. This happens transparently and you don’t need to do anything. However, you can modify the behavior by creating user attributes that affect how AppJail interprets them when starting the D-Bus proxy.
$ x11appjail attr put appjail4win:default.dbus-user.talk.notifications "org.freedesktop.Notifications"
By defining this attribute, notifications will work as if they were running on your host. Note that this is just an example, and the application running within the jail may or may not use notifications.
Both the session bus and the system bus can be completely disabled by simply setting <appname>:<profile>.dbus-user or <appname>:<profile>.dbus-system to none. The system bus is usually disabled by default, as in most cases only the session bus is needed.
$ x11appjail attr put appjail4win:default.dbus-user none
Note that if you have already started the AppJail, in order for the changes to take effect, you must destroy the jail and then run the AppJail again.
$ x11appjail destroy-jail appjail4win
Keyboard and mouse reference (Openbox)
The Openbox environment uses the following key and mouse bindings. They are
defined in Openbox’s rc.xml.
Note: W means the Super key (usually the Windows key), and S
means Shift.
Keyboard bindings
| Binding |
Action |
W-q |
Close the active window (Close) |
W-S-q |
Exit Openbox with confirmation (Exit with prompt=yes) |
W-f |
Toggle fullscreen (ToggleFullscreen) |
W-w |
Go to the next window (NextWindow) |
W-S-w |
Go to the previous window (PreviousWindow) |
W-l |
Show the combined client list menu (ShowMenu > client-list-combined-menu) |
Mouse bindings
| Context |
Button / action |
Resulting action |
| Frame (window frame) |
W-Left (Press) |
Focus and raise the window (Focus, Raise) |
|
W-Left (Click) |
Unshade the window (Unshade) |
|
W-Left (Drag) |
Move the window (Move) |
|
W-Right (Press) |
Focus, raise, and unshade (Focus, Raise, Unshade) |
|
W-Right (Drag) |
Resize the window (Resize) |
|
W-Middle (Press) |
Lower the window to the bottom (Lower, FocusToBottom, Unfocus) |
| Titlebar |
Left (Drag) |
Move the window (Move) |
|
Left (DoubleClick) |
Toggle maximize (ToggleMaximize) |
|
Up (Click) |
Shade the window if it is not shaded (Shade conditional) |
|
Down (Click) |
Unshade the window if it is shaded (Unshade conditional) |
| Titlebar Top Right Bottom Left TLCorner TRCorner BRCorner BLCorner |
Left (Press) |
Focus, raise, and unshade (Focus, Raise, Unshade) |
|
Middle (Press) |
Lower to the bottom (Lower, FocusToBottom, Unfocus) |
|
Right (Press) |
Focus, raise, and show the client menu (ShowMenu > client-menu) |
| Top (top edge) |
Left (Drag) |
Resize from the top edge (Resize edge top) |
| Left (left edge) |
Left (Drag) |
Resize from the left edge (Resize edge left) |
| Right (right edge) |
Left (Drag) |
Resize from the right edge (Resize edge right) |
| Bottom (bottom edge) |
Left (Drag) |
Resize from the bottom edge (Resize edge bottom) |
|
Right (Press) |
Focus, raise, and show the client menu (ShowMenu > client-menu) |
| TRCorner BRCorner TLCorner BLCorner (corners) |
Left (Press) |
Focus, raise, and unshade (Focus, Raise, Unshade) |
|
Left (Drag) |
Resize (Resize) |
Note: W-Left, W-Right, and W-Middle mean that you must hold the
Super key while clicking the left, right, or middle mouse button,
respectively.
Prerequisites
-
Install and configure Overlord.
The easiest way to do this is to use AppJail.setup with the --with-overlord parameter. See also Getting Started in the AppJail Handbook.
-
Configure your Overlord instance with a label that uniquely identifies it across the entire cluster. For example, in my case:
/usr/local/etc/overlord.yml (excerpt):
labels:
- all
- desktop
- services
- vm-only
- dc-air
desktop is that label.
-
Download a Windows ISO and place it in /var/cache/x11appjail/appjail4win/iso. This AppJail will change the file mode to 0700 for this directory, since your autounattend.xml file may contain sensitive data.
-
(optional) Create an autounattend.xml file. You can use this generator to do so.
The location could be /var/cache/x11appjail/appjail4win/xml, but this AppJail doesn’t actually care about the path, so you can put it anywhere, as long as it’s a secure location.
Recommendations
Networking
If you use this generator to create an autounattend.xml file, include at least the following in “XML markup for more components":
-
<Interfaces>
<Interface wcm:action="add">
<Ipv4Settings>
<DhcpEnabled>false</DhcpEnabled>
<Metric>10</Metric>
<RouterDiscoveryEnabled>false</RouterDiscoveryEnabled>
</Ipv4Settings>
<Identifier>Ethernet</Identifier>
<UnicastIpAddresses>
<IpAddress wcm:action="add" wcm:keyValue="1">192.168.8.2/24</IpAddress>
</UnicastIpAddresses>
<Routes>
<Route wcm:action="add">
<Identifier>0</Identifier>
<Metric>10</Metric>
<NextHopAddress>192.168.8.1</NextHopAddress>
<Prefix>0.0.0.0/0</Prefix>
</Route>
</Routes>
</Interface>
</Interfaces>
to the “Microsoft-Windows-TCPIP — specialize” component.
-
<Interfaces>
<Interface wcm:action="add">
<DNSServerSearchOrder>
<IpAddress wcm:action="add" wcm:keyValue="1">172.16.0.1</IpAddress>
</DNSServerSearchOrder>
<Identifier>Ethernet</Identifier>
</Interface>
</Interfaces>
to the “Microsoft-Windows-DNS-Client — specialize” component.
Please note that this assumes you have followed the Getting Started guide in the AppJail Handbook. Feel free to use whatever works best for your environment.
Block outbound traffic from the host to jails for users with UID > 0
VNC on bhyve does not use authentication. Although you can rely on Windows authentication (bad idea), it is advisable to further restrict unprivileged users at network-level so that they cannot connect to jails by default. This can be done with --enable-pf-unprivileged-block in AppJail.setup. It is assumed that Security Group hooks are installed, so we will use them throughout the rest of this document.
Installed AppJail
Although you can use this AppJail in portable mode, keep in mind that in this mode you can only use the default profile. We recommend installing this AppJail with different profiles, as described below:
$ doas ./appjail4win.AppJail --install --set-option profile=win10
$ doas ./appjail4win.AppJail --install --set-option profile=win11
Creating Windows VM
Configuring
The system operator (that is, you, with root privileges) is responsible for configuring the AppJail before unprivileged users run it.
At a minimum, you need the following system attributes:
overlord.label: The label under which the VM will be deployed.
<appspec>.isofile: Filename of the ISO file, which is supposed to be located in /var/cache/x11appjail/appjail4win/iso.
As an AppJail secret, you must have an access token for your Overlord instance as overlord/access_token:
$ OVERLORD_CONFIG=/usr/local/etc/overlord.yml overlord gen-token |\
appjail secrets create overlord/access_token
There are other system attributes that this AppJail supports, but only the ones listed above are required. An example from my system, including the optional ones:
General:
$ doas x11appjail sys-attr put overlord.label desktop
Windows 10:
$ doas x11appjail sys-attr put appjail4win:win10.res 1280x720
$ doas x11appjail sys-attr put appjail4win:win10.cpu 4
$ doas x11appjail sys-attr put appjail4win:win10.mem 4G
$ doas x11appjail sys-attr put appjail4win:win10.isofile es-es_windows_10_enterprise_ltsc_2021_x64_dvd_51d721ea.iso
$ doas x11appjail sys-attr put appjail4win:win10.template /var/cache/x11appjail/appjail4win/templates/win10.yml
$ doas x11appjail sys-attr put appjail4win:win10.autounattend /var/cache/x11appjail/appjail4win/xml/autounattend.xml
$ doas ls -lh /var/cache/x11appjail/appjail4win/iso/es-es_windows_10_enterprise_ltsc_2021_x64_dvd_51d721ea.iso
-rw-r--r-- 1 root wheel 4,6G 31 oct. 18:53 /var/cache/x11appjail/appjail4win/iso/es-es_windows_10_enterprise_ltsc_2021_x64_dvd_51d721ea.iso
Windows 11:
$ doas x11appjail sys-attr put appjail4win:win11.res 1280x720
$ doas x11appjail sys-attr put appjail4win:win11.cpu 4
$ doas x11appjail sys-attr put appjail4win:win11.mem 4G
$ doas x11appjail sys-attr put appjail4win:win11.root.storage 64G
$ doas x11appjail sys-attr put appjail4win:win11.isofile en-us_windows_11_iot_enterprise_ltsc_2024_x64_dvd_f6b14814.iso
$ doas x11appjail sys-attr put appjail4win:win11.template /var/cache/x11appjail/appjail4win/templates/win11.yml
$ doas x11appjail sys-attr put appjail4win:win11.autounattend /var/cache/x11appjail/appjail4win/xml/autounattend.xml
$ doas ls -lh /var/cache/x11appjail/appjail4win/iso/en-us_windows_11_iot_enterprise_ltsc_2024_x64_dvd_f6b14814.iso
-rw-r--r-- 1 root wheel 4,8G 22 nov. 14:09 /var/cache/x11appjail/appjail4win/iso/en-us_windows_11_iot_enterprise_ltsc_2024_x64_dvd_f6b14814.iso
<appspec>.template is completely optional, and if none is specified, this AppJail will use the built-in one. The problem is that, although the default template is generic enough, it may not work on your system. For example, it won’t work on my system because I use Security Groups and need to explicitly allow DNS, at a minimum. Additionally, in certain cases, you may want to enable other features, such as sound, TPM, etc., which requires allowing specific devices within the jail. You’ll find more details in the “Customization” section.
Profit!
Once the system operator has configured the AppJails, an unprivileged user can now run the installed AppJails.
$ x11appjail list | grep appjail4win
appjail4win win10 6.1M
appjail4win win11 6.1M
$ x11appjail run appjail4win:win10

This AppJail creates two disks for different purposes: a primary (or root) disk and a secondary (or private) disk. The first is intended for the operating system and is ephemeral, while the second is for you, to store user data that will remain even after the vmjail is recreated. Note that the secondary disk is only created if it does not already exist, but it is not formatted. It is recommended that you format it using Windows itself. The secondary disk is stored as /var/x11appjail/users/<uid>/<appspec>/data.img.
$ ls -lh /var/x11appjail/users/15000/appjail4win.win10/data.img
-rw------- 1 user user 10G 23 nov. 16:02 /var/x11appjail/users/15000/appjail4win.win10/data.img

If you have used an autounattend.xml file, this AppJail will create a new ISO file that includes it. That ISO file is the one that will be used in this case.
$ ls -ld /var/cache/x11appjail/appjail4win/iso
drwx------ 2 root wheel 7 23 nov. 15:42 /var/cache/x11appjail/appjail4win/iso
$ doas ls -lh /var/cache/x11appjail/appjail4win/iso/appjail4win:win10.iso
-rw-r--r-- 1 root wheel 4,6G 23 nov. 15:42 /var/cache/x11appjail/appjail4win/iso/appjail4win:win10.iso
This AppJail will recreate the ISO file only if the autounattend.xml file is newer than the ISO file. The ISO file will not be recreated if you have modified <appspec>.isofile or if that file has been modified. You can touch(1) your autounattend.xml or remove the ISO file, but the first option is recommended, as it will not affect any ongoing operations.
Once AppJail detects that the VM is ready to accept connections and no errors have been detected, vncviewer is used to connect to the VNC session created by bhyve(8). This happens inside the jail, but you can easily connect from the host using vncviewer or any other VNC client you have.
$ nc -z -v winvm-appjail4win-15000_win10 5900
Connection to winvm-appjail4win-15000_win10 5900 port [tcp/vnc-server] succeeded!
$ vncviewer -FullScreen=0 winvm-appjail4win-15000_win10
If you run this AppJail again after everything has gone smoothly, this AppJail will simply reconnect (and possibly start the VM, if the guest OS has shut down).
$ x11appjail run appjail4win:win10
...
Starting winvm-appjail4win-15000_win10
* found guest in /vm/winvm-appjail4win-15000_win10
* booting...
...
[*] Waiting for 10.0.0.5:5900 without a timeout
[+] 10.0.0.5:5900 is available after 1 seconds
...
TigerVNC v1.16.2
Built on: 2026-11-15 15:06
Copyright (C) 1999-2026 TigerVNC team and many others (see README.rst)
See https://www.tigervnc.org for information on TigerVNC.
Mon Nov 23 18:36:15 2026
DecodeManager: Detected 4 CPU core(s)
DecodeManager: Creating 4 decoder thread(s)
CConn: Connected to host 10.0.0.5 port 5900
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8
CConnection: Choosing security type None(1)
DesktopWindow: Reducing window size to fit on current monitor
Mon Nov 23 18:36:16 2026
CConn: Throughput 20000 kbit/s - full color is now enabled
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Throughput 19999 kbit/s - changing to quality 8
...
From the user’s perspective, there is no difference between running Windows 10 and Windows 11, except for the profile:
$ x11appjail run appjail4win:win11

Customization
You may need to customize the settings if the default values do not suit your environment. For example, these are the Overlord deployment files I used to install Windows 10 and Windows 11:
$ doas x11appjail sys-attr cat appjail4win:win10.template
/var/cache/x11appjail/appjail4win/templates/win10.yml
$ cat /var/cache/x11appjail/appjail4win/templates/win10.yml
kind: vmJail
datacenters:
main:
entrypoint: !ENV 'http://127.0.0.1:${WINVM_OVERLORD_PORT}'
access_token: !ENV '${WINVM_ACCESS_TOKEN}'
deployIn:
labels:
- !ENV '${WINVM_LABEL}'
vmName: !ENV '${WINVM_NAME}'
makejail: 'gh+AppJail-makejails/vm'
overwrite: true
options:
- fstab: !ENV '${WINVM_DATASTORE} /vm/.iso nullfs ro'
- fstab: !ENV '${X11APPJAIL_USERDIR} /media'
- device: 'path dsp unhide'
- device: 'path "dsp*" unhide'
- label: 'security-group:1'
- label: 'security-group.tables.allow-dns:allow-dns'
- label: !ENV 'security-group.rules.allow-vnc:pass out on appjail_bridge proto tcp to %i port 5900 user ${X11APPJAIL_UID}'
- sysrc: 'create_args_bridge0=ether 02:00:00:00:00:01'
build-arguments:
- is_public_vm: '1'
- exclude_ports: '5900'
template:
loader: 'uefi'
cpu: !ENV '${WINVM_CPU}'
memory: !ENV '${WINVM_MEM}'
sound: 'yes'
graphics: 'yes'
graphics_listen: '0.0.0.0'
graphics_res: !ENV '${WINVM_RES}'
graphics_wait: 'no'
xhci_mouse: 'yes'
network0_type: 'virtio-net'
network0_switch: 'public'
network0_mac: !ENV '${WINVM_MACADDR}'
utctime: 'NO'
wired_memory: 'YES'
uefi_vars: 'YES'
debug: 'YES'
disk1_type: 'nvme'
disk1_dev: 'custom'
disk1_name: '/media/data.img'
disk2_type: 'ahci-cd'
disk2_dev: 'custom'
disk2_name: '/vm/.iso/virtio-win.iso'
virt_console0: 'org.qemu.guest_agent.0'
diskLayout:
driver: 'nvme'
size: !ENV '${WINVM_STORAGE}'
from:
type: 'iso'
isoFile: !ENV '${WINVM_ISOFILE}'
$ doas x11appjail sys-attr cat appjail4win:win11.template
/var/cache/x11appjail/appjail4win/templates/win11.yml
$ cat /var/cache/x11appjail/appjail4win/templates/win11.yml
kind: vmJail
datacenters:
main:
entrypoint: !ENV 'http://127.0.0.1:${WINVM_OVERLORD_PORT}'
access_token: !ENV '${WINVM_ACCESS_TOKEN}'
deployIn:
labels:
- !ENV '${WINVM_LABEL}'
vmName: !ENV '${WINVM_NAME}'
makejail: 'gh+AppJail-makejails/vm'
overwrite: true
options:
- fstab: !ENV '${WINVM_DATASTORE} /vm/.iso nullfs ro'
- fstab: !ENV '${X11APPJAIL_USERDIR} /media'
- device: 'path dsp unhide'
- device: 'path "dsp*" unhide'
- device: 'path "tpm*" unhide'
- label: 'security-group:1'
- label: 'security-group.tables.allow-dns:allow-dns'
- label: !ENV 'security-group.rules.allow-vnc:pass out on appjail_bridge proto tcp to %i port 5900 user ${X11APPJAIL_UID}'
- sysrc: 'create_args_bridge0=ether 02:00:00:00:00:01'
build-arguments:
- is_public_vm: '1'
- exclude_ports: '5900'
template:
loader: 'uefi'
cpu: !ENV '${WINVM_CPU}'
memory: !ENV '${WINVM_MEM}'
sound: 'yes'
graphics: 'yes'
graphics_listen: '0.0.0.0'
graphics_res: !ENV '${WINVM_RES}'
graphics_wait: 'no'
xhci_mouse: 'yes'
network0_type: 'virtio-net'
network0_switch: 'public'
network0_mac: !ENV '${WINVM_MACADDR}'
utctime: 'NO'
wired_memory: 'YES'
uefi_vars: 'YES'
debug: 'YES'
disk1_type: 'nvme'
disk1_dev: 'custom'
disk1_name: '/media/data.img'
disk2_type: 'ahci-cd'
disk2_dev: 'custom'
disk2_name: '/vm/.iso/virtio-win.iso'
virt_console0: 'org.qemu.guest_agent.0'
bhyve_options: '-l tpm,passthru,/dev/tpm0'
diskLayout:
driver: 'nvme'
size: !ENV '${WINVM_STORAGE}'
from:
type: 'iso'
isoFile: !ENV '${WINVM_ISOFILE}'
There aren’t many differences between win10.yml and win11.yml. What they have in common are the devices required for sound to work on the guest OS. In my case, I downloaded virtio-win.iso, which my autounattend.xml file can automatically detect and install. Other common parameters include labels related to Security Group rules, which in my case allow DNS and permit the unprivileged user to connect to the vmjail, assuming you used --enable-pf-unprivileged-block in AppJail.setup. For Windows 11, there are parameters related to the TPM, which is supposed to be exposed on your host as /dev/tpm0.
Please note that if you do not configure the bridge’s MAC address, the if_bridge(4) driver will choose a random one. Windows detects this change and, after restarting the jail, will begin referring to the network as “Network 2,” “Network 3,” and so on. However, the sysrc option is only available in AppJail >5.9.2.
Tor
Since this AppJail is based on gh+AppJail-makejails/vm, it is possible to deploy a VM in which all traffic is routed through Tor. However, a few minor changes are required. In your autounattend.xml file, you must change the DNS settings to point to 192.168.8.1 instead of 172.16.0.1 (or whatever nameserver you’ve been using). The rest of the system attributes are similar to those of, in this case, Windows 10, but you’ll need to slightly modify the template.
$ doas x11appjail sys-attr cat appjail4win:tor.autounattend
/var/cache/x11appjail/appjail4win/xml/autounattend+tor.xml
$ doas x11appjail sys-attr cat appjail4win:tor.res
1280x720
$ doas x11appjail sys-attr cat appjail4win:tor.cpu
4
$ doas x11appjail sys-attr cat appjail4win:tor.isofile
es-es_windows_10_enterprise_ltsc_2021_x64_dvd_51d721ea.iso
$ doas x11appjail sys-attr cat appjail4win:tor.mem
4G
$ doas x11appjail sys-attr cat appjail4win:tor.template
/var/cache/x11appjail/appjail4win/templates/tor.yml
$ cat /var/cache/x11appjail/appjail4win/templates/tor.yml
kind: vmJail
datacenters:
main:
entrypoint: !ENV 'http://127.0.0.1:${WINVM_OVERLORD_PORT}'
access_token: !ENV '${WINVM_ACCESS_TOKEN}'
deployIn:
labels:
- !ENV '${WINVM_LABEL}'
vmName: !ENV '${WINVM_NAME}'
makejail: 'gh+AppJail-makejails/vm'
overwrite: true
options:
- fstab: !ENV '${WINVM_DATASTORE} /vm/.iso nullfs ro'
- fstab: !ENV '${X11APPJAIL_USERDIR} /media'
- label: 'security-group:1'
- label: 'security-group.tables.allow-dns:allow-dns'
- label: !ENV 'security-group.rules.allow-vnc:pass out on appjail_bridge proto tcp to %i port 5900 user ${X11APPJAIL_UID}'
- sysrc: 'create_args_bridge0=ether 02:00:00:00:00:01'
build-arguments:
- vm_tag: 'tor'
template:
loader: 'uefi'
cpu: !ENV '${WINVM_CPU}'
memory: !ENV '${WINVM_MEM}'
graphics: 'yes'
graphics_listen: '0.0.0.0'
graphics_res: !ENV '${WINVM_RES}'
graphics_wait: 'no'
xhci_mouse: 'yes'
network0_type: 'virtio-net'
network0_switch: 'public'
network0_mac: !ENV '${WINVM_MACADDR}'
utctime: 'NO'
wired_memory: 'YES'
uefi_vars: 'YES'
debug: 'YES'
disk1_type: 'nvme'
disk1_dev: 'custom'
disk1_name: '/media/data.img'
disk2_type: 'ahci-cd'
disk2_dev: 'custom'
disk2_name: '/vm/.iso/virtio-win.iso'
virt_console0: 'org.qemu.guest_agent.0'
diskLayout:
driver: 'nvme'
size: !ENV '${WINVM_STORAGE}'
from:
type: 'iso'
isoFile: !ENV '${WINVM_ISOFILE}'
$ doas ./appjail4win.AppJail --install --set-option profile=tor
$ x11appjail run appjail4win:tor

Commands and Login
Attentive readers will have noticed that, in my templates, I have specified org.qemu.guest_agent.0, a socket for communicating with the QEMU guest agent, assuming it is installed on the guest OS. This AppJail installs hooks (a feature available in x11appjail v3.0.0 and later), so when you run x11appjail run-cmd, the commands are executed on the guest OS.
$ x11appjail run-cmd appjail4win:tor whoami
nt authority\system
$ x11appjail run-cmd appjail4win:tor ipconfig
Configuraci�n IP de Windows
Adaptador de Ethernet Ethernet:
Sufijo DNS espec�fico para la conexi�n. . :
V�nculo: direcci�n IPv6 local. . . : fe80::6c72:ca4d:ac70:5e19%6
Direcci�n IPv4. . . . . . . . . . . . . . : 192.168.8.2
M�scara de subred . . . . . . . . . . . . : 255.255.255.0
Puerta de enlace predeterminada . . . . . : 192.168.8.1
$ x11appjail run-cmd appjail4win:tor powershell.exe -Command "(Invoke-RestMethod -Uri 'http://ip-api.com/json').query"
204.8.96.116
A similar hook is installed for x11appjail login with the sole purpose of locking the screen on the guest.
$ x11appjail login appjail4win:tor

Packages
In the "Run custom scripts > FirstLogon Scripts” section of the generator mentioned above, you can enter the following script to install chococaley and any other packages you want on your VM:
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
choco install notepadplusplus -y --no-progress
This will install Notepad++, but you can install any other package you want.

Persistent data
As mentioned earlier, the primary drive is erased every time the vmjail is recreated, so all data stored on it is lost and you have to start from scratch. The most practical solution is to use the secondary drive created by this AppJail to store the data you want to keep. However, you’ll need to make some adjustments in Windows so that programs and user data are stored on the secondary drive. Fortunately, this can be done right in the generator mentioned earlier in the “Run custom scripts > DefaultUser scripts” section.
$folders = @{
'Desktop' = 'Desktop'
'Personal' = 'Documents'
'{374DE290-123F-4565-9164-39C4925E467B}' = 'Downloads'
'My Pictures' = 'Pictures'
'My Video' = 'Videos'
'My Music' = 'Music'
'Favorites' = 'Favorites'
'{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}' = 'Saved Games'
'{56784854-C6CB-462B-8169-88E350ACB882}' = 'Contacts'
'{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}' = 'Searches'
'{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}' = 'Links'
}
$base = 'D:\UserData\%USERNAME%'
$userShell = 'HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
foreach ($regName in $folders.Keys) {
reg.exe add $userShell /v $regName /t REG_EXPAND_SZ /d "$base\$($folders[$regName])" /f | Out-Null
}
$scriptPath = 'C:\Windows\Setup\Scripts\CreateJunctions.ps1'
$scriptContent = @'
if (-not (Test-Path -LiteralPath 'D:\')) { return }
$usf = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders')
foreach ($name in $usf.GetValueNames()) {
$raw = $usf.GetValue($name, $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
$p = [Environment]::ExpandEnvironmentVariables($raw)
if ($p -like 'D:\UserData\*' -and -not (Test-Path -LiteralPath $p)) {
New-Item -ItemType Directory -Path $p -Force | Out-Null
}
}
$usf.Close()
$userBase = "D:\UserData\$env:USERNAME"
$links = @{ "$env:APPDATA\Notepad++" = Join-Path $userBase 'AppData\Notepad++' }
foreach ($link in $links.Keys) {
$target = $links[$link]
if (-not (Test-Path -LiteralPath $target)) { New-Item -ItemType Directory -Path $target -Force | Out-Null }
if (Test-Path -LiteralPath $link) {
$item = Get-Item -LiteralPath $link -Force
if ($item.LinkType -eq 'Junction') { continue }
Get-ChildItem -LiteralPath $link -Force | Move-Item -Destination $target -Force
Remove-Item -LiteralPath $link -Force
}
New-Item -ItemType Junction -Path $link -Target $target | Out-Null
}
'@
New-Item -ItemType Directory -Path (Split-Path $scriptPath) -Force | Out-Null
Set-Content -LiteralPath $scriptPath -Value $scriptContent -Encoding ASCII
$vbs = @'
Set sh = CreateObject("WScript.Shell")
sh.Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -File ""C:\Windows\Setup\Scripts\CreateJunctions.ps1""", 0, False
'@
Set-Content -LiteralPath 'C:\Windows\Setup\Scripts\CreateJunctions.vbs' -Value $vbs -Encoding ASCII
$runCmd = 'wscript.exe "C:\Windows\Setup\Scripts\CreateJunctions.vbs"'
reg.exe add "HKU\DefaultUser\Software\Microsoft\Windows\CurrentVersion\Run" /v "AppJailJunctions" /t REG_SZ /d $runCmd /f
The only problem is that the D: drive might not be formatted. To avoid having to install Windows just to format the disk, you can run the x11appjail create command, create the disk image, and then use mkntfs from filesystems/ntfs to format it.
x11appjail create appjail4win:win10
truncate -s 10G /var/x11appjail/users/15000/appjail4win.win10/data.img
md=$(doas mdconfig -at vnode -f /var/x11appjail/users/15000/appjail4win.win10/data.img)
doas gpart create -s gpt ${md}
doas gpart add -t ms-reserved -s 16M ${md}
doas gpart add -t ms-basic-data ${md}
doas env NTFS_USE_UBLIO=0 mkntfs -F -f -L "AppJail" /dev/${md}p2
doas mdconfig -du ${md}

The scripts above preserve not only some subdirectories of the user directory, but also the Notepad++'s AppData directory. Of course, you’ll need to adapt this script to your environment, but at the very least, it’s a good starting point.

VM as template
Although appjail4win creates a reproducible Windows installation in combination with an autounattend.xml file, it is somewhat inefficient when you have to recreate the virtual machine over and over again. An alternative is to use an IMG image with an existing Windows installation, so that you can create a virtual machine for the sole purpose of serving as a “template” and then use its disk file to create new virtual machines. However, this means you cannot use the autounattend.xml file on this new virtual machine. This workflow is similar to that of OCI with a Containerfile and an OCI image, or to that of AppJail images and a Makejail, where an image is created and then used to deploy new instances.
In Windows, the recommended way to clone is to use Sysprep to generalize the image, which can be combined with another autounattend.xml file. The reason for using two autounattend.xml files is that the first one is for the base VM and the other is for the clones. The first is the one you used with appjail4win, and the second is the one you must transfer (for example, via SSH or RDP) to your base VM to use with Sysprep.
C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /shutdown /mode:vm /unattend:C:\unattend.xml
/mode:vm: Use this only if you plan to use the image with the same hypervisor (in this case, bhyve) and the same “hardware.”
/unattend:C:\unattend.xml: Use this only if you have transferred an autounattend.xml file to your base VM. In this case, the path is C:\unattend.xml.
Unlike Persistent Data, you must use a variant of that script, since it uses the regedit to create the subdirectories in D:\, but the username is already created in C:\, so you must use the following script to move the data to D:\:
$userName = 'Admin'
$profileRoot = "C:\Users\$userName"
$dataRoot = "D:\UserData\$userName"
if (-not (Test-Path -LiteralPath $profileRoot)) {
Write-Host "Profile '$profileRoot' does not exist yet. Skipping redirection."
return
}
$shellFolders = @{
'Desktop' = 'Desktop'
'Personal' = 'Documents'
'{374DE290-123F-4565-9164-39C4925E467B}' = 'Downloads'
'My Pictures' = 'Pictures'
'My Video' = 'Videos'
'My Music' = 'Music'
'Favorites' = 'Favorites'
'{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}' = 'Saved Games'
'{56784854-C6CB-462B-8169-88E350ACB882}' = 'Contacts'
'{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}' = 'Searches'
'{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}' = 'Links'
}
$appJunctions = @{
'AppData\Roaming\Notepad++' = 'AppData\Notepad++'
}
$hivePath = Join-Path $profileRoot 'NTUSER.DAT'
$regLoaded = $false
try {
reg.exe load "HKU\TargetUser" "$hivePath" 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) { $regLoaded = $true }
} catch { }
if (-not $regLoaded) {
Write-Host "Failed to load '$hivePath'. Skipping Shell Folders redirection."
}
if ($regLoaded) {
try {
foreach ($sub in $shellFolders.Values) {
$p = Join-Path $dataRoot $sub
if (-not (Test-Path -LiteralPath $p)) {
New-Item -ItemType Directory -Path $p -Force | Out-Null
}
}
$regPath = 'HKU\TargetUser\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
foreach ($name in $shellFolders.Keys) {
$p = Join-Path $dataRoot $shellFolders[$name]
reg.exe add $regPath /v $name /t REG_EXPAND_SZ /d "$p" /f | Out-Null
}
} finally {
reg.exe unload "HKU\TargetUser" 2>&1 | Out-Null
}
}
foreach ($relLink in $appJunctions.Keys) {
$link = Join-Path $profileRoot $relLink
$target = Join-Path $dataRoot $appJunctions[$relLink]
$targetExists = Test-Path -LiteralPath $target
if (-not $targetExists) {
New-Item -ItemType Directory -Path $target -Force | Out-Null
}
if (Test-Path -LiteralPath $link) {
$item = Get-Item -LiteralPath $link -Force
if ($item.LinkType -eq 'Junction') {
continue
}
if ($targetExists) {
Remove-Item -LiteralPath $link -Recurse -Force
} else {
Get-ChildItem -LiteralPath $link -Force |
Move-Item -Destination $target -Force
Remove-Item -LiteralPath $link -Force
}
}
New-Item -ItemType Junction -Path $link -Target $target | Out-Null
}
Place it under “Run custom scripts > System scripts” section.
Assuming you have appjail4win:win10, as mentioned in this document, you must stop the virtual machine, copy the disk0.img file to /var/cache/x11appjail/appjail4win/img, and create some system attributes for the new virtual machine. The other change is our template, which will be slightly different.
doas appjail cmd jexec winvm-appjail4win-15000_win10 vm stop winvm-appjail4win-15000_win10
sync
d=$(doas appjail cmd local winvm-appjail4win-15000_win10 realpath vm/winvm-appjail4win-15000_win10/disk0.img)
doas cp -a "${d}" /var/cache/x11appjail/appjail4win/img/win10.img
-
$ x11appjail sys-attr put appjail4win:test.cpu 4
$ x11appjail sys-attr put appjail4win:test.imgfile win10.img
$ x11appjail sys-attr put appjail4win:test.mem 4G
$ x11appjail sys-attr put appjail4win:test.res 1280x720
$ x11appjail sys-attr put appjail4win:test.template /var/cache/x11appjail/appjail4win/templates/test.yml
doas ./appjail4win.AppJail --install --set-option profile=test
x11appjail run appjail4win:test
Depending on what you want to do, you might want to remove appjail4win:win10 by running x11appjail destroy-jail appjail4win:win10, just in case you don’t want to modify this virtual machine. Or, if you’d rather do it later, simply run doas appjail jail boot off winvm-appjail4win-15000_win10, and your virtual machine won’t start at startup.
/var/cache/x11appjail/appjail4win/templates/test.yml:
kind: vmJail
datacenters:
main:
entrypoint: !ENV 'http://127.0.0.1:${WINVM_OVERLORD_PORT}'
access_token: !ENV '${WINVM_ACCESS_TOKEN}'
deployIn:
labels:
- !ENV '${WINVM_LABEL}'
vmName: !ENV '${WINVM_NAME}'
makejail: 'gh+AppJail-makejails/vm'
overwrite: true
options:
- fstab: !ENV '${WINVM_DATASTORE} /vm/.img nullfs ro'
- fstab: !ENV '${X11APPJAIL_USERDIR} /media'
- device: 'path dsp unhide'
- device: 'path "dsp*" unhide'
- label: 'security-group:1'
- label: 'security-group.tables.allow-dns:allow-dns'
- label: !ENV 'security-group.rules.allow-vnc:pass out on appjail_bridge proto tcp to %i port 5900 user ${X11APPJAIL_UID}'
- sysrc: 'create_args_bridge0=ether 02:00:00:00:00:01'
build-arguments:
- is_public_vm: '1'
- exclude_ports: '5900'
template:
loader: 'uefi'
cpu: !ENV '${WINVM_CPU}'
memory: !ENV '${WINVM_MEM}'
sound: 'yes'
graphics: 'yes'
graphics_listen: '0.0.0.0'
graphics_res: !ENV '${WINVM_RES}'
graphics_wait: 'no'
xhci_mouse: 'yes'
start_slot: '5'
network0_type: 'virtio-net'
network0_switch: 'public'
network0_mac: !ENV '${WINVM_MACADDR}'
utctime: 'NO'
wired_memory: 'YES'
uefi_vars: 'YES'
debug: 'YES'
disk1_type: 'nvme'
disk1_dev: 'custom'
disk1_name: '/media/data.img'
virt_console0: 'org.qemu.guest_agent.0'
diskLayout:
driver: 'nvme'
size: !ENV '${WINVM_STORAGE}'
from:
type: 'img'
imgFile: !ENV '${WINVM_IMGFILE}'
In previous deployments, since we introduced virtio-win.iso, our network interface will use a different slot than the one specified above. Windows will detect this change and label the interface as “Ethernet 2”; furthermore, the configuration will be lost, and you’ll have to reconfigure the interface manually. To avoid this, we use start_slot, and this way Windows will be happy.
Attributes
User Attributes
| Name |
Description |
<appspec>.dbus-system |
Configure the system bus mode. There are three modes:
1. filter: Enables filtering. 2. unfiltered: Disables filtering. This mode is insecure and is recommended only for development. 3. none: Completely disables the session bus. This is the default mode unless explicitly stated otherwise.
|
<appspec>.dbus-system.<policy>.* |
Apply a policy or rule to the system bus, where <type> can be own, call, talk, see, and broadcast. See xdg-dbus-proxy(1) for details. |
<appspec>.dbus-user |
Configure the session bus mode. There are three modes:
1. filter: Enables filtering. This is the default mode unless explicitly stated otherwise. 2. unfiltered: Disables filtering. This mode is insecure and is recommended only for development. 3. none: Completely disables the session bus.
|
<appspec>.dbus-user.<policy>.* |
Apply a policy or rule to the session bus, where <type> can be own, call, talk, see, and broadcast. See xdg-dbus-proxy(1) for details. |
<appspec>.dpi |
Sets the resolution for all screens, in dots per inch. By default, no DPI is set. |
<appspec>.env.<label>.* |
User-defined custom environment variables. <label> is an arbitrary name, as it is not part of the environment. The value of the attribute will be the environment variable with its value in the format <name>=<value>. |
<appspec>.jail.ephemeral |
Mark the jail as ephemeral. See ephemeral option in appjail-quick(1) for details.
Although the jail may be destroyed, its data is preserved in the user directory (see ${X11APPJAIL_USERDIR} in x11appjail-spec(5)).
|
<appspec>.nofullscreen |
Prevents devilspie2 from setting windows to full screen when they can be maximized. |
<appspec>.screen |
Screen size. If this is not set, allow the window to be resized. |
System Attributes
| Name |
Description |
<appspec>.autounattend |
Path to the autounattend.xml file for installing Windows in unattended mode. |
<appspec>.cpu |
Number of CPUs to be used for this virtual machine. |
<appspec>.imgfile |
IMG filename containing an existing installation of the Windows operating system. |
<appspec>.isofile |
ISO filename containing the Windows operating system. |
<appspec>.labels |
A space-separated list of label names. |
<appspec>.macaddr |
This option allows you to specify a mac address to use for this interface. Default is 58:9c:fc:00:00:01. |
<appspec>.mem |
The amount of memory to assign to the guest. |
oci.from |
Location of OCI image. |
oci.pull-policy |
Pull policy. Default is newer.
See --pull in buildah-from(1) for details.
|
oci.tag |
OCI image tag. |
overlord.label |
A label that matches the local instance of Overlord. |
overlord.port |
The port on which the local Overlord instance is listening. Default is 8888. |
<appspec>.labels.<label> |
The value of the label. |
<appspec>.oci.from |
Same as oci.from, but by application. It takes precedence when defined. |
<appspec>.oci.pull-policy |
Same as oci.pull-policy, but by application. It takes precedence when defined. |
<appspec>.oci.tag |
Same as oci.tag, but by application. It takes precedence when defined. |
<appspec>.private.storage |
Storage size of the secondary disk. Default is 10G.
Please note that if this disk file does not exist, it will be created, but this only happens once. This AppJail will not change the disk size, so you must use truncate(1) to do so at your own risk.
|
<appspec>.res |
Specify the resolution of the graphical console in WxH format. Only a certain range of resolutions are currently supported (see graphics_res in config.sample). Default is 1024x768. |
<appspec>.root.storage |
Storage size of the primary disk. Default is 30G. |
network.security-group.tables |
If network.mode is set to virtualnet, this attribute specifies a space-separated list of pf(4) tables to which the jail will be added using Security Group hooks.
If you are going to add additional labels related to Security Groups, do not include security-group:1, as this attribute already include it.
See also: https://github.com/DtxdF/AppJail/wiki/filter
|
mount.system-fonts |
Read-only mounts the fonts system inside the jail, configure Fontconfig, and rebuild the font cache. |
<appspec>.template |
Overlord deployment file. |
OCI Configuration
build:
variants:
- tag: 15.1
containerfile: Containerfile
aliases: ["latest"]
default: true
args:
FREEBSD_RELEASE: "15.1"
NO_PKGCLEAN: "1"
cache_dirs: ["pkgcache0:/var/cache/pkg"]
评论