v0.7.0

Sandbox

Last updated


HakoRun wraps the runtime in an OS-native sandbox on every run: Bubblewrap on Linux, seatbelt on macOS.

Linux: systemd-run + bwrap


internal/sandbox/command_linux.go builds systemd-run --scope --user --quiet --slice=hakorun.slice -- bwrap ... -- <runtime> /wrapper.<ext>.
AspectSetting
Namespaces--unshare-all, --unshare-net (no network)
Privileges--cap-drop ALL, --new-session, --die-with-parent
FilesystemRead-only /usr, /lib, /lib64, and the wrapper; tmpfs /tmp and /home/sandbox; fresh /proc and /dev
Working directory/tmp
EnvironmentHOME=/home/sandbox, PATH=/usr/local/bin:/usr/bin:/bin, TMPDIR=/tmp, LANG=C.UTF-8; unsets LD_PRELOAD, LD_LIBRARY_PATH
TypeScript extraMounts the project root read-only and points NODE_PATH at its node_modules

Because only /usr is mounted, the global tsx must live under /usr (npm's default /usr/local prefix works); bwrap fails to start on systems without /lib64.

macOS: sandbox-exec


The command is sandbox-exec -p <profile> <runtime> <wrapper>, with the profile from seatbeltProfile():
  1. (version 1)
  2. (deny default)
  3. (allow process-exec)
  4. (allow process-fork)
  5. (allow sysctl-read)
  6. (allow mach-lookup)
  7. (allow signal)
  8. (allow ipc-posix*)
  9. (allow file-read*)
  10. (allow file-write* (subpath "<HOME>"))
  11. (allow network*)

Platform Comparison


AspectLinuxmacOS
NetworkDisabledAllowed
Writestmpfs only$HOME only
ReadsMounted paths onlyEverywhere
Resource capshakorun.sliceNone
EnvironmentResetInherits the server's

The macOS boundary is much wider and suits development; serve production traffic from Linux.

中文