When building a scripting language, safety tools often get pigeonholed into a single bucket. We tend to view sandboxing strictly as defensive security, and dry-runs strictly as developer convenience.

In Rye, features like Linux namespaces (unshare), filesystem allowlists (Landlock), and Intents serve a dual purpose depending on which hat you are wearing:

  1. For your own code: They turn dangerous side effects into observable, rehearsal-friendly data structures.
  2. For untrusted code: They act as lightweight, zero-overhead OS micro-jails.

Here is how these three primitives do double duty.


1. Intents: Rehearsals and Side-Effect Auditing

A naive dry-run relies on scattered if dry_run: checks. But I/O Intents do something fundamentally deeper: they force you to explicitly annotate every point in your codebase that mutates the outside world.

Instead of hiding file writes, database updates, or HTTP POSTs deep inside obscure helper functions, an output-intent turns mutation into a first-class event:

; Wrap I/O operations in structured intents
output-intent: fn { meta blk } {
    if rye .Is-dry-run {
        print "INTENT [DRY-RUN]: " + (meta |to-json)
    } else {
        print "INTENT [EXEC]: " + (meta |to-json)
        do blk
    }
}

; Usage
output-intent { action: "write-report", path: "%/tmp/summary.json" } {
    write %/tmp/summary.json report-data
}

Why this has dual value:

  • In Development (Rehearsal): With --dry-run, the block is bypassed, logging exactly what would have happened without risk.
  • In Production (Auditing & Traceability): Even during live execution, you instantly get a clean, structured audit log of every environment modification your script performs. Every I/O point in your application becomes explicit and observable.

2. Unshare: Modern Dry-Runs and Untrusted Code Jails

Command-line execution of random Gists, npm scripts, or LLM-generated code is normally a game of Russian Roulette. Give a script local execution rights, and it can read ~/.ssh, exfiltrate AWS keys, or wipe your disk.

Rye’s --unshare flag leverages Linux namespaces (user, mount, net, pid, uts) at startup.

# Run a snippet with no network and a jailed filesystem
rye --unshare untrusted_script.rye
; Inside the script: enforce that execution is sandboxed before proceeding
rye .Require-unshared

Why this has dual value:

  • For Untrusted Scripts (Containment): The kernel maps the process to a temporary tmpfs jail, mounts CWD at /app, strips outbound network interfaces, and drops root capabilities. If a pasted snippet tries to exfiltrate secrets or touch /etc, the kernel blocks it dead in its tracks.
  • For Local Rehearsals (Strict Isolation): Combined with --dry-run, --unshare guarantees that even if a dry-run script tries to bypass language-level checks, it physically cannot leak data across the network or alter host files.

3. Landlock: Soft Constraints and Hard Guards

While unshare creates a macro-jail at startup, Landlock provides unprivileged, fine-grained access control from within your script.

; Initialize Landlock pipeline
ll: rye .Landlock
ll | landlock//Limit-to-cwd             ; Allow reading current directory
ll | landlock//Allow %/tmp/artifacts    ; Allow writes ONLY to a specific output dir
ll | landlock//Enforce                  ; One-shot, process-lifetime lock

Why this has dual value:

  • For Safe Refactoring: When writing complex local tooling, you can lock down the filesystem after reading configuration files. That way, a buggy loop or inverted path string can never accidentally overwrite your source code.
  • For CI/CD Pipeline Safety: In shared CI runners, Landlock guarantees that runaway build scripts or malicious pull-request code cannot pollute host directories outside the designated artifact folder.

The Big Picture

Primitive Used for Developer Experience (DX) Used for Runtime Security
Intents Structured --dry-run simulations & local mocking. Complete audit trail of all environment-mutating code points.
Unshare Guarantees dry runs can’t accidentally talk to live networks. Zero-overhead sandbox for running untrusted third-party code.
Landlock Catching path bugs during complex local script runs. Enforcing immutable file boundaries on third-party dependencies.

Safety tools shouldn’t feel like enterprise bureaucracy. By combining kernel-level boundaries with explicit code annotations, Rye gives developers risk-free rehearsals for their own code and instant containment for everyone else’s.