alias npm='aa-exec -p sandbox npm'
alias node='aa-exec -p sandbox node'
sandbox profile: # /etc/apparmor.d/sandbox
include <tunables/global>
profile sandbox {
#include <abstractions/base>
#include <abstractions/consoles>
#include <abstractions/nameservice>
/sys/** r,
/{usr/,}bin/* ixr,
# nodejs install dir
owner /home/*/nodejs/**/* rix,
owner /tmp/** rw,
owner /tmp/**/ rw,
owner /home/*/.npm/_* lrw,
owner /home/*/.npm/_*/ lrw,
owner /home/*/.npm/_*/** lrw,
owner /home/*/.npmrc r,
owner /home/**/node_modules/ rwix,
owner /home/**/node_modules/** rwix,
owner /home/**/package.json rw,
owner /home/**/package-lock.json rw,
owner /home/*/projects/**/ r,
owner /home/*/projects/** r,
}
To load the profile:sudo apparmor_parser -r /etc/apparmor.d/sandbox
edit: For completeness, added step to load the profile.