{"id":2726,"date":"2022-01-13T02:38:56","date_gmt":"2022-01-13T02:38:56","guid":{"rendered":"https:\/\/dft.wiki\/?p=2726"},"modified":"2026-04-20T14:19:27","modified_gmt":"2026-04-20T18:19:27","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 access specific resources and protect the operating system from vulnerabilities and threats.<\/p>\n<ol>\n<li>AppArmor\n<ol>\n<li>Used profiles that define what known applications need to perform their tasks and provide those minimum resources.<\/li>\n<\/ol>\n<\/li>\n<li>Firejail\n<ol>\n<li>An incredibly easy-to-use way to simply spin up an application from the terminal with a few arguments as needed.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Additionally, I also mentioned how to use the <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 application called <code>proychains<\/code> that tunnel all traffic over a Proxy server or even use the Tor Network.<\/p>\n<hr \/>\n<p><strong>APPARMOR<\/strong><\/p>\n<p>AppArmor is a Kernel Enhancement that allows for sandboxing applications, giving it only the minimum amount of resources that it needs to perform its tasks, but nothing else.<\/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, use the following syntax:<\/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>Execute any application with Firejail to apply restrictions or limitations:<\/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 over the Bridge Interface<span style=\"font-size: 1rem;\">.<\/span><\/p>\n<hr \/>\n<p><strong>BONUS<br \/>\n<\/strong><\/p>\n<p>Restrict the desired application to only run through the desired network interface, such as a VPN, for example.<\/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 create additional rules to guarantee it is still accessible from the local network on specific ports while restricted to using the VPN interface to reach the Internet.<\/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 examples of usage and configuration for ProxyChains [<a href=\"https:\/\/dft.wiki\/?p=1635#ProxyChains\">Link<\/a>] to learn how to restrict a specific application to strictly use the Tor Network.<\/p>\n<p><strong>Open Snitch<\/strong> and <strong>Little Snitch<\/strong><\/p>\n<p>Monitor and intercept requests to start a new network connection, allowing one to approve or deny before it happens.<\/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 for MacOS only)<\/li>\n<\/ul>\n<p>Available for Downloads 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 access specific resources and protect the [&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":10,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2726\/revisions"}],"predecessor-version":[{"id":5469,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/2726\/revisions\/5469"}],"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}]}}