Documentation

Sandbox

How go-faas isolates multi-language user code on Linux and macOS.

Platform Strategy

Platform Entry command Isolation
Linux systemd-run + bwrap User slice resource caps + Bubblewrap namespaces
darwin sandbox-exec Seatbelt profile (dev-oriented)

Production hardening targets Linux. macOS support exists so the API can be developed on Apple hosts.

Linux: systemd Slice

On startup, sandbox.NewSlice() writes ~/.config/systemd/user/go-faas-slice and reloads user systemd:

Setting Source Default
CPUQuota MAX_CPUS * 100 percent 100% (1 core)
MemoryMax MAX_MEMORY 128M
MemorySwapMax fixed 0

Each run uses systemd-run --scope --user --quiet --slice=go-faas-slice -- bwrap ....

Linux: Bubblewrap

SandboxCommand (linux build) assembles bwrap flags including:

Python runs as python3 -u /wrapper.py; JS/TS as node|tsx /wrapper.*.

macOS: sandbox-exec

Darwin build generates a seatbelt profile that:

NewSlice() is a no-op on darwin.

Process I/O Contract

Regardless of platform, the child process:

  1. Reads one JSON payload on stdin: code + input strings
  2. Writes intermediate logs and final JSON result on stdout
  3. Writes failures on stderr (SSE path treats stderr as fatal)

Handlers own timeouts via context.WithTimeout around exec.CommandContext.

Dependency Checker

Linux checker.CheckPackage() may install bubblewrap, nodejs, npm, and python3 through apt/dnf/pacman/apk when Node, TypeScript (tsc), esbuild, or Python are missing. Darwin checker is a no-op.

中文