Files
pmg/sandbox/platform/platform_linux.go
T

38 lines
1.1 KiB
Go
Raw Normal View History

2026-01-13 14:52:02 +05:30
//go:build linux
// +build linux
package platform
import (
"os"
"github.com/safedep/dry/log"
2026-01-13 14:52:02 +05:30
"github.com/safedep/pmg/sandbox"
)
// NewSandbox creates a platform-specific sandbox instance for Linux.
// Prefers Landlock (kernel 5.13+) with seccomp-notify for deny enforcement.
// Falls back to Bubblewrap if Landlock or seccomp-notify is unavailable.
// Set PMG_SANDBOX_DRIVER=bubblewrap to force Bubblewrap, or
// PMG_SANDBOX_DRIVER=landlock to force Landlock (no fallback — fails if
// Landlock is unavailable).
2026-01-13 14:52:02 +05:30
func NewSandbox() (sandbox.Sandbox, error) {
switch os.Getenv("PMG_SANDBOX_DRIVER") {
case "bubblewrap":
log.Debugf("PMG_SANDBOX_DRIVER=bubblewrap: forcing Bubblewrap sandbox")
return newBubblewrapSandbox()
case "landlock":
log.Debugf("PMG_SANDBOX_DRIVER=landlock: forcing Landlock sandbox")
return newLandlockSandbox()
}
sb, err := newLandlockSandbox()
if err == nil {
log.Debugf("Using Landlock sandbox driver (ABI V%d)", sb.(*landlockSandbox).abi.Version)
return sb, nil
}
log.Debugf("Landlock not available (%v), falling back to Bubblewrap", err)
return newBubblewrapSandbox()
2026-01-13 14:52:02 +05:30
}