Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

srid/sandnix

A Nix flake-parts module for wrapping programs with a sandboxed environment using landrun (Landlock) on Linux, and sandbox-exec on macOS.

srid/sandnix.json
{
"createdAt": "2025-10-10T23:09:16Z",
"defaultBranch": "master",
"description": "A Nix flake-parts module for wrapping programs with a sandboxed environment using landrun (Landlock) on Linux, and sandbox-exec on macOS.",
"fullName": "srid/sandnix",
"homepage": "",
"language": "Nix",
"name": "sandnix",
"pushedAt": "2026-03-06T20:00:16Z",
"stargazersCount": 39,
"topics": [],
"updatedAt": "2026-03-16T14:29:50Z",
"url": "https://github.com/srid/sandnix"
}

GitHub Discussions

A Nix flake-parts module for wrapping programs with a sandboxed environment using landrun (Landlock) on Linux, and sandbox-exec on macOS.

In your flake.nix:

{
inputs.sandnix.url = "github:srid/sandnix";
outputs = { flake-parts, sandnix, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ sandnix.flakeModule ];
perSystem = { pkgs, ... }: {
sandnixApps.my-app-sandboxed = {
program = "${pkgs.my-app}/bin/my-app";
features = {
tty = true; # Terminal support
nix = true; # Nix store access (default)
network = true; # Network access
tmp = true; # /tmp access (default)
};
# Raw arguments to pass to `landrun` CLI
cli = {
rw = [ "$HOME/.config/my-app" ];
rox = [ "/etc/hosts" ];
};
};
};
};
}

Run with: nix run .#my-app-sandboxed

sandnix provides reusable modules for common applications via sandnixModules.*. These can be imported into your app configurations:

{
inputs.sandnix.url = "github:srid/sandnix";
outputs = { flake-parts, sandnix, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ sandnix.flakeModule ];
perSystem = { pkgs, ... }: {
sandnixApps.my-app = {
imports = [
sandnix.sandnixModules.gh # Import GitHub CLI module
];
program = "${pkgs.my-app}/bin/my-app";
features.network = true;
};
};
};
}
ModuleDescription
sandnixModules.ghGitHub CLI (gh) configuration with D-Bus keyring support
sandnixModules.gitGit configuration with TTY support and repository access
sandnixModules.haskellHaskell tooling with Cabal configuration and state directory access
sandnixModules.markitdownMarkitdown configuration with /proc/cpuinfo access

Sandbox Claude Code with access to project directory, config files, and network.

See [examples/claude-sandboxed]!(./examples/claude-sandboxed/flake.nix) for a complete working example.

Try it:

Terminal window
nix run 'github:srid/sandnix?dir=examples/claude-sandboxed'

High-level feature flags automatically configure common sandboxing patterns:

FeatureDefaultDescription
features.ttyfalseTTY devices, terminfo, locale env vars
features.nixtrueNix store, system paths, PATH env var
features.networkfalseDNS resolution, SSL certificates, unrestricted network
features.tmptrueRead-write access to /tmp
features.dbusfalseD-Bus session bus, keyring access for Secret Service API

Fine-grained control via cli.*:

OptionDescription
roxRead-only + execute paths
roRead-only paths
rwxRead-write-execute paths
rwRead-write paths
envEnvironment variables to pass through
unrestrictedNetworkAllow all network access
addExecAuto-add executable to rox (default: true)

https://github.com/srid/sandnix/discussions

GPL-3.0

  • nixpak: a fancy declarative wrapper around bubblewrap.
  • jail.nix: helper to make it easy and ergonomic to wrap your derivations in bubblewrap.