Repository navigation
Release 0.10.0
Cordon 0.10.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
Preset::Crystal- Lets thecrystalcompiler build, run and spec programs inside the cordon, on macOS and Linux. It grants a cache directory and a temp directory read-write and pointsCRYSTAL_CACHE_DIRandTMPDIRat them. On macOS it also grants the developer tools and setsPATHandSDKROOT, socc,ldand the SDK are found withoutxcrun, whose cache sits in the temporary folder every application shares. On Linux it grants/etc/alternativesand/usr/libexec/gccwhere present, through which Debian-family systems reachccand GCC'scollect2. It grants neither the compiler, nor/bin/sh, nor the network: mergePreset::BrewandPreset::System, and grant network yourself if a command needs it.with_temp_dirandbuild-Preset::Crystal.with_temp_dir(cache_dir:)creates a private temp directory (mode0700, underDir.tempdir), yields the preset and deletes the directory when the block ends, however it ends.Preset::Crystal.build(cache_dir:, temp_dir:)takes a directory you manage yourself. Merge the preset last, and change its directories only through these arguments: settingCRYSTAL_CACHE_DIRorTMPDIRin another policy moves the variable but not the grant. On macOS, pass your ownPATHaspath_env:if your policy sets one.- The compiler cache is the caller's choice - The compiler links a cached object file whenever new code compiles to identical bitcode, so a command that can write to a cache can plant code a later build links.
cache_dirtherefore has no default. Give each sandboxed use a cache of its own, or opt in to the one your own builds use withPreset::Crystal.shared_cache_dir, which finds it the way the compiler does, and accept that the sandbox can write code your next unsandboxed build may link. - CLI:
--crystal-cache DIR-cordon runandcordon inspectmerge the Crystal preset withDIRas its cache, or the shared cache whenDIRisshared, in a fresh temp directory per invocation:cordon run --add brew --add system --crystal-cache ~/.cache/cordon/crystal -- crystal spec. - CLI: a warning when
--envor--unset-envoverrides a preset's variable - The preset's grant for the old value stays, and the new value gets none.cordonnow says so on standard error rather than leaving the command to fail, or to reach a directory you meant to withdraw.
Known issues
Preset::Crystalgrants no network, soshards installandshards updateneed--allow-network(orallow_networkin the policy). Without it,gitfails to clone because its HTTPS helper cannot read/etc/ssl/openssl.cnf, which the macOS runner grants only with network access. With it they work, verified on macOS; sinceHOMEis not passed through, shards keeps its cache in the project's.shardsdirectory rather than~/.cache/shards.Preset::Crystalis verified on macOS with the Command Line Tools and on Ubuntu; Xcode.app installs and other Linux distributions are not yet tested. Windows is unsupported:buildraisesUnsupportedPlatformError.- Linux:
Preset::Systemdoes not grant/etc/alternatives, so on Debian-family systems tools reached through it, such asawk,editorandpager, are not found inside the sandbox. - 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.