{"id":2726,"date":"2022-01-13T02:38:56","date_gmt":"2022-01-13T02:38:56","guid":{"rendered":"https:\/\/dft.wiki\/?p=2726"},"modified":"2026-06-08T21:58:25","modified_gmt":"2026-06-09T01:58:25","slug":"sandboxing-applications-with-apparmor-firejail-and-more","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=2726","title":{"rendered":"Sandboxing Applications with AppArmor, Firejail and More"},"content":{"rendered":"<p>Sandboxing is a technique for confining an application to specific resources, protecting the operating system from vulnerabilities and threats.<\/p>\n<ol>\n<li>AppArmor\n<ol>\n<li>Uses profiles that define what a known application needs to perform its tasks and provides only those minimum resources.<\/li>\n<\/ol>\n<\/li>\n<li>Firejail\n<ol>\n<li>An easy-to-use tool to launch an application from the terminal with a few arguments as needed.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Additionally, I covered how to use <code>iptables<\/code> to restrict applications by <code>uid<\/code> or <code>gid<\/code> to only use a VPN connection (<code>tun0<\/code> from OpenVPN), and the tool <code>proxychains<\/code> to tunnel all traffic through a proxy server or the Tor Network.<\/p>\n<hr \/>\n<p><strong>APPARMOR<\/strong><\/p>\n<p>AppArmor is a kernel enhancement that sandboxes applications, giving them only the minimum resources needed to perform their tasks.<\/p>\n<pre>sudo apt install apparmor-profiles apparmor-utils -y\r\nsudo aa-status<\/pre>\n<p>To enforce all profiles or a single profile:<\/p>\n<pre>sudo aa-enforce \/etc\/apparmor.d\/*\r\nsudo aa-enforce \/etc\/apparmor.d\/usr.sbin.traceroute<\/pre>\n<hr \/>\n<p><strong>FIREJAIL<\/strong><\/p>\n<p>Firejail is a SUID program that reduces the risk of security breaches by restricting the running environment of untrusted or vulnerable applications with low overhead.<\/p>\n<pre>sudo apt install firejail firejail-profiles -y\r\nfirejail --help<\/pre>\n<p>Run any application through Firejail to apply restrictions:<\/p>\n<pre>firejail --net=none firefox\r\nfirejail --net=tun0 firefox<\/pre>\n<p>Other examples:<\/p>\n<pre>firejail --private --dns=8.8.8.8 --hosts-file=\/etc\/hosts firefox\r\nfirejail --net=eth0 --defaultgw=192.168.1.1 firefox\r\nfirejail --cpu=2,3 firefox<\/pre>\n<p>Limiting bandwidth:<\/p>\n<pre>firejail --name=slow --private --net=eth0 firefox -no-remote\r\nfirejail --bandwidth=slow set eth0 200 100<\/pre>\n<p>Optionally, create a bridge network (using <code>bridge-utils<\/code> and <code>uml-utilities<\/code>) attached to the VPN interface and force the desired application through it.<\/p>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>Restrict an application to only run through a specific network interface, such as a VPN.<\/p>\n<pre>sudo iptables -A OUTPUT -m owner --uid-owner debian-transmission \\! -o tun0 -j REJECT\r\nsudo -u debian-transmission transmission-gtk &amp;<\/pre>\n<p>Or add rules to keep it accessible on the local network on specific ports while still restricting its internet traffic to the VPN interface.<\/p>\n<pre>sudo iptables -A OUTPUT -d 192.168.0.0\/16 -p tcp --sport 9091 -m owner --gid-owner debian-transmission -o wlan0 -j ACCEPT\r\nsudo iptables -A OUTPUT -d 192.168.0.0\/16 -p udp --sport 9091 -m owner --gid-owner debian-transmission -o wlan0 -j ACCEPT\r\nsudo iptables -A OUTPUT -m owner --gid-owner debian-transmission -o tun0 -j ACCEPT\r\nsudo iptables -A OUTPUT -m owner --gid-owner debian-transmission -o lo -j ACCEPT\r\nsudo iptables -A OUTPUT -m owner --gid-owner debian-transmission -j REJECT<\/pre>\n<p>See also the next post with ProxyChains usage and configuration examples [<a href=\"https:\/\/dft.wiki\/?p=1635#ProxyChains\">Link<\/a>] to learn how to restrict a specific application to the Tor Network.<\/p>\n<p><strong>Open Snitch<\/strong> and <strong>Little Snitch<\/strong><\/p>\n<p>Monitor and intercept new network connection requests, with the ability to approve or deny them before they go through.<\/p>\n<ul>\n<li>Open Snitch<\/li>\n<\/ul>\n<pre>sudo apt install opensnitch -y\r\nopensnitch-ui<\/pre>\n<ul>\n<li>Little Snitch (originally macOS only)<\/li>\n<\/ul>\n<p>Available for download at [<a href=\"https:\/\/obdev.at\/products\/littlesnitch-linux\/download.html\">Link<\/a>].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sandboxing is a technique for confining an application to specific resources, protecting the operating system [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2726","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2726"}],"version-history":[{"count":11,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2726\/revisions"}],"predecessor-version":[{"id":5692,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2726\/revisions\/5692"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}