Repository navigation
Release 0.9.0
Cordon 0.9.0
Cordon is a Crystal shard that runs shell commands inside a platform-native sandbox with a configurable access policy. It works on macOS (via sandbox-exec / Seatbelt), Linux (via bwrap / Bubblewrap) and, as a preview, Windows 11 (via Microsoft's MXC wxc-exec.exe), presenting all three as a single clean API.
Changes
- Breaking, macOS: the sandbox no longer inherits your environment - A sandboxed command on macOS used to see every variable of the process that started it. It now starts with a small passthrough set (
PATH,TERM,LANG,LC_ALL,LANGUAGE,TZandPWD), plus whateverPolicy#envsets (#24). If a command relied on another variable, such asHOME,TMPDIRor a tool's own setting, add it toenv.TMPDIRin particular is better pointed at a directory of the sandbox's own, granted read-write, than at the per-user temporary folder every application shares. - macOS:
Policy#envandPolicy#unset_envare honoured - They were silently ignored before.unset_envalso removes passthrough variables, as on Linux and Windows. - macOS:
Policy#working_diris honoured - The command used to start in the caller's directory whateverworking_dirsaid; the directory was only granted. It now starts inworking_dir, as on Linux and Windows, withPWDnaming it. A relative command such as./toolis now found relative toworking_dir. - Breaking, macOS:
working_dirno longer grants access - When no path list coveredworking_dir, macOS quietly granted it read-write; Linux and Windows never did. Add the directory toread_write_pathsorread_only_pathsif the command needs it. - CLI:
--env KEY=VALUEand--unset-env KEY-cordon runandcordon inspectcan now set and remove variables inside the sandbox, overriding the policy file. Both repeat, and the last flag for a name wins. Policy files never expand$NAME, so this is where a value built from your own environment goes:--env PATH="/opt/tools/bin:$PATH". - macOS: the notification-center rule in
BASELINEtakes effect - It matched the shared-memory name withliteral, which matches only file paths, so it never applied and tools such asldanddsymutillogged a denial each time they started. It now usesipc-posix-name, and those reads are allowed as intended. - macOS:
Cordon.relaunchworks - Its depth counter travels inPolicy#env, so on macOS the relaunched program never saw it, tried to relaunch again, and failed. - Runner implementers:
Launch#envandLaunch#chdir- ALaunchcan now carry the complete environment its launcher starts with, and the directory it starts in;run,spawnandexecapply both. The protectedexecutetakes theLaunchrather than its argv. Code that only calls Cordon is unaffected.
Known issues
- macOS: a sandboxed process can create semaphores under
/CRYSTAL/. Semaphore names are shared across the machine, so it could take the name another Crystal program needs for its next thread, or exhaust the system's semaphore limit. Both are denial of service, not escape; Cordon does not limit a sandboxed process's resources in any case. - macOS: killing a spawned command ends that process only; processes it started keep running, still sandboxed, and can hold the caller's pipes open. Linux and Windows end the whole process tree (#47).
- Windows: MXC 1.0.0 no longer carries the "early preview, not a security boundary" warning of earlier releases, but PSEC is new and may change between Windows updates. Cordon pins the MXC version it is tested against; re-run
cordon confirmafter Windows updates (#41). - Windows: a batch file (
.bat,.cmd) can only be run withshell: true, because its arguments cannot be quoted safely. - Windows: tested on Windows 11 Enterprise 25H2, on ARM (a VM and GitHub's Windows 11 ARM runner, with
cordon.exeunder x64 emulation) and on an x64 laptop, wherecordon.exeruns natively. Other editions such as Windows 11 Pro are not yet tested. - Windows: the process security environment arrives with recent Windows 11 25H2 updates. A laptop on build 26200.8893 lacked it and gained it on 26200.9448; if
check-windows.ps1reports it unavailable, install the latest updates and check again. - Windows: only an x64
cordon.exeis built; ARM machines run it under emulation (#39). - Windows:
cordon.exeis unsigned, and some endpoint security products flag the statically linked executable as suspicious (#40). - Windows: everything under
C:\Windowsis readable and executable in the sandbox without a grant (#38). - Windows: PowerShell 7, Git Bash, toolchains installed per user, and junctions or symlinks inside granted paths are not yet validated (#34, #35, #36).
For architecture, design decisions, and debugging workflows see DEVELOPMENT.md.