Repository navigation
Cordon 0.10.2
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
- Ruby: gems from
GEM_HOMEandGEM_PATH- The sandbox does not inherit your environment, so gems that a version manager keeps outside Ruby's defaults were not found. chruby, for one, setsGEM_HOMEto~/.gem/ruby/<full version>, where Ruby looks in~/.gem/ruby/<API version>.Preset::Ruby.for_executablenow takes optionalgem_home:andgem_path:: each directory that exists is granted read-only, and the variable is set. Nothing is read from the environment unless you pass it:for_executable(path, gem_home: ENV["GEM_HOME"]?, gem_path: ENV["GEM_PATH"]?). A directory that does not exist yet still gets the variable, but no grant. The static presets take no such arguments. - CLI:
--ruby-gem-env- With--ruby,cordon runandcordon inspectpass their ownGEM_HOMEandGEM_PATHto the preset:cordon run --ruby $(which ruby) --ruby-gem-env -- ruby script.rb. It is an error without--ruby, and warns when neither variable is set.--rubyalone still reads nothing from your environment. - Ruby: the user gem directory is granted only if it exists - The presets granted
~/.gemunconditionally, whichbwrapcannot bind when it is absent, and missed the directory RubyGems uses instead in that case,~/.local/share/gem. They now grant whichever of the two exists.Preset::Ruby.user_gem_dirsreturns them. - Python:
for_venvactivates the venv -Preset::Python.for_venvnow setsVIRTUAL_ENVand puts the venv's executables directory (bin, orScriptson Windows) first onPATH, as the venv'sactivatescript does. Before,python3was the venv's only if your own shell had activated it, so a sandbox started elsewhere ran the base interpreter without the venv's packages. The newpath_env:argument, which defaults to yourPATH, is what follows the venv's directory. The preset'sPATHreplaces yours on merge, asPreset::Crystal's does on macOS, so merge it last or pass your ownPATHaspath_env:. - Docs: toolchain variables -
DEVELOPMENT.mdnow records which variables each toolchain needs in a cleared environment and why the others are left out, with the checks behind it.
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.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.- Python and Ruby test suites that write temporary files need a
TMPDIRthe policy grants: without one,tempfileandDir.tmpdirfall back to/tmp, which the macOS runner does not grant. Grant a directory read-write and setTMPDIRinpolicy.env. - Merging
Preset::Python.for_venvwithPreset::Crystalon macOS leaves only thePATHof whichever is merged last. - 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.