I didn’t set out to build a security framework for a scripting language; I just wanted to stop shooting myself in the foot.
When running random scripts locally or in CI, safety comes down to three basic mechanisms:
- Namespaces (
unshare) — A kernel wrapper that strips network access and hides the rest of your filesystem. - Landlock — An unprivileged, process-level allowlist that restricts filesystem writes to specific directories.
- Intents (
dry-run) — An application-level pattern to declare and rehearse side effects without executing them.
These tools aren’t a grand manifesto. They are small habits that turn risky local scripts into safe defaults. Here is how they work in Rye, how they compose, and where they save you.
The Rye API Paradigm
Before looking at the features, note how Rye exposes its core capabilities. System-level features are attached to a dedicated value-kind (Rye-itself) accessible via the rye word:
; Basic posture checks
rye .Is-unshare ; returns boolean
rye .Unshare-config? ; returns {active fs net pid uts}
rye .Require-unshared ; exits(1) if not unshared (ideal CI guard)
; Landlock builder pipeline
ll: rye .Landlock
ll | landlock//Limit-to-cwd
ll | landlock//Allow %/tmp/out
ll | landlock//Enforce
1. Unshare: Linux Namespace Isolation
The Problem
You paste a snippet from a Gist to clean up a repository. Unbeknownst to you, it tries to phone home to a remote API and delete files outside your current directory.
The Mechanism
By launching your script with --unshare, Rye re-execs itself inside isolated Linux user, mount, network, PID, and UTS namespaces:
- Filesystem Jail: Creates a temporary
tmpfsjail at/tmp/rye_jail_<pid>, bind-mounts your current working directory to/app, and pivots root into it. - Network Isolation: Stubs out outbound network interfaces by default.
- PID & Procfs: Makes the child process PID 1 within its own isolated namespace and mounts a clean
/proc.
# Run completely isolated
rye --unshare myscript.rye
# Opt back into network access if needed
rye --unshare --unshare-net=false myscript.rye
Inside your script, you can inspect or enforce this posture dynamically:
; Assert sandbox state in CI pipelines
rye .Require-unshared
; Branch logic based on network posture
if rye .Is-unshare-net {
print "Offline mode active"
} else {
print "Online mode active"
}
Caveat:
unshareis Linux-only and occurs at process startup. It cannot be toggled on or off mid-execution.
2. Landlock: Precise Filesystem Allowlists
The Problem
A flaky test suite occasionally writes temporary artifacts directly into your project root instead of /tmp, cluttering your git working tree.
The Mechanism
While unshare handles macro-isolation at startup, Landlock provides unprivileged, fine-grained access control from inside your code. You can define exact path allowlists before performing risky I/O operations.
; 1. Initialize the builder
ll: rye .Landlock
; 2. Define the allowlist
ll | landlock//Limit-to-cwd ; Allow project tree
ll | landlock//Allow %/tmp/ci-artifacts ; Allow explicitly created temp dir
; 3. Enforce the ruleset (one-shot, irreversible for process lifetime)
ll | landlock//Enforce
; Permitted write
write %/tmp/ci-artifacts/report.json (to-json data)
Rule of Thumb: Always apply
unshareflags at the CLI level first, then apply Landlock in code. This ensures Landlock paths evaluate against the jailed filesystem view.
3. Intents: Rehearsing Side Effects
The Problem
You are writing a deployment or reporting script and need to verify what it will write without actually modifying disk or making live external calls.
The Mechanism
Intents decouple the declaration of an action from its execution. By combining custom intent wrappers with Rye’s built-in --dry-run flag (rye .Is-dry-run), you can simulate side effects safely.
Output Intents (Controlled Writes)
; Define an intent wrapper
output-intent: fn { meta blk } {
if rye .Is-dry-run {
print "DRY-RUN: " + (meta |to-json)
} else {
do blk
}
}
; Usage
output-intent { file: "/tmp/report.html", note: "Render final report" } {
write %/tmp/report.html html-content
}
Running rye --dry-run script.rye will output "DRY-RUN: {"file":"/tmp/report.html", ...}" without touching the filesystem.
Input Intents (Offline Fixtures)
You can also use intents to swap live network requests for local fixtures when operating inside an isolated namespace:
fetch-data: fn { } {
if rye .Is-unshare-net {
; Return local offline fixture when isolated
(intent.input.http "GET https://api.internal/data")
} else {
cc batteries
http-get "https://api.internal/data"
}
}
Real-World Composition Recipes
Strict CI Pipeline
Ensure tests run completely isolated without network leaks or uncontrolled disk access:
; Guard script against un-sandboxed environments
rye .Require-unshared
; Lock down filesystem
ll: rye .Landlock
ll | landlock//Limit-to-cwd
ll | landlock//Allow %/tmp/artifacts
ll | landlock//Enforce
; Run pipeline with dry-run logging if flag present
if rye .Is-dry-run { print "Simulating CI pipeline run..." }
Local Development Safety Net
Default to running local scripts with rye --unshare .. Write temporary output to /tmp, branch gracefully when rye .Is-unshare-net is true, and use --dry-run to inspect side effects before committing changes.
Summary
| Mechanism | Scope | Key Benefit |
|---|---|---|
| Unshare | OS / Kernel | Drops global system visibility and disables network on startup. |
| Landlock | Process / FS | Restricts file access to explicit directory allowlists mid-run. |
| Intents | Application | Allows simulation (--dry-run) and fixture swapping for side effects. |
By combining kernel namespaces, filesystem allowlists, and execution intents, you get safe execution environments by default—without needing full container engines like Docker for simple local tasks.