A --dry-run flag is a promise: run this command, and it will tell you what it would do without actually doing it.
The implementation is often a boolean.
That boolean has no authority over the filesystem, the network, or the helper function someone added last Tuesday. Every part of the program has to remember to cooperate.
I’ve been working on runtime safety features in Rye, a scripting language. One question keeps pulling these features together:
Can a dry run depend less on my remembering to implement the dry run?
Linux can enforce some useful boundaries here. But getting the boundaries right exposes a distinction: preventing a script from changing things is not the same as showing what a successful execution would do.
The forgotten write
Consider a cleanup script:
def cleanup(paths, dry_run=False):
for path in paths:
if dry_run:
print(f"Would delete {path}")
else:
os.remove(path)
record_cleanup(path)
The deletion respects the flag. What does record_cleanup do?
Perhaps it prints a message. Perhaps it appends to a local file. Perhaps it updates a database to say that the file was deleted.
The last possibility is particularly unpleasant: the dry run preserves the file but records that it was removed.
Passing dry_run into record_cleanup might fix this example. Then its helpers need the flag too. This can be managed with good architecture and tests, but the guarantee remains cooperative: every side-effecting path must follow the policy.
I would like two things instead:
- A convenient way for cooperating code to describe an action without performing it.
- A boundary that rejects prohibited actions even when a helper forgets to cooperate.
These are different jobs.
First, make the planned action visible
Rye has blocks that can be passed to functions without executing them. That makes a small wrapper around an operation straightforward.
The following is the shape of an output-intent helper. It is application code, not an automatic interception of all I/O:
output-intent: fn { description action } {
either rye .Is-dry-run {
print description
} {
do action
}
}
The helper accepts a description and a block. During a dry run it prints the description. Otherwise it evaluates the block.
A call might look like this:
output-intent "Would write the cleanup report" {
write %cleanup-report.txt report
}
In a larger tool, the description could be structured metadata: operation, destination, and reason. That would support machine-readable plans or a more useful display than a stream of messages.
But the plain version makes the important boundary visible: describing the action is separate from executing it.
It also makes the limitation visible. A direct write elsewhere in the script bypasses this helper. The wrapper is a convention, not a security boundary. Its description can even disagree with its block.
We have improved the cooperative part of dry-run mode. We haven’t enforced the promise yet.
Then give the promise a boundary
Linux Landlock lets an unprivileged process restrict its own access to filesystem resources. Once restrictions are in place, an ordinary function cannot opt out of them just because it forgot about dry_run.
That changes the forgotten-write example.
With an appropriately configured read-only filesystem policy:
- The intent wrapper can describe the planned report without writing it.
- A helper that accidentally tries to create a file is denied by the kernel.
The first path is a rehearsal. The second is a detected violation of the rehearsal’s rules.
Rye exposes a Landlock builder through rye .Landlock. But the important part isn’t the spelling of that API. It is the exact policy it installs.
“Only access the current directory” is not the same policy as “read the current directory, but do not modify it.” A path allowlist alone doesn’t tell us which actions are allowed there.
A trustworthy dry-run mode needs explicit answers:
- Which filesystem operations are restricted?
- Which paths are readable, and which, if any, remain writable?
- What happens if the kernel doesn’t support the required restrictions?
- What authority was already available through open file descriptors?
- Are restrictions applied to every executing thread that matters?
That last question matters for a runtime implemented in Go, like Rye. A policy attached to one OS thread is not automatically evidence that every runtime thread is confined.
For a mode advertised as enforced, a failed setup must stop execution. Printing a warning and continuing would turn a hard boundary back into a request to be careful.
The network is also a place you can write
A filesystem policy does not, by itself, make an HTTP request harmless.
A cleanup helper might send a webhook. A migration script might update a remote database. Even a request that looks like a read can trigger server-side effects.
Rye also has a startup isolation option:
rye --dry-run --unshare cleanup.rye
The two flags have different responsibilities:
--dry-runmakes the rehearsal mode available to cooperating script code.--unsharesets up namespace isolation, including a separate network namespace by default.
The intended network boundary is that the script has no ordinary route to external services. Namespace isolation still needs careful setup: inherited sockets and other already-open resources cannot simply be ignored when making that claim.
The filesystem side also needs care. Rye’s current namespace setup attempts to mount the project read-only, but that remount is best-effort. That is not sufficient grounds to advertise guaranteed read-only execution. A strict mode would need to reject a failed remount or establish an equivalent enforced policy before running the script.
This is why I prefer to discuss the actual boundary rather than say “the script is sandboxed.” Sandboxed how? With what still available inside it?
What a convincing test would look like
A successful dry run isn’t much evidence by itself. Perhaps the script simply didn’t try anything dangerous.
The more useful test deliberately violates the rules:
| Attempt during rehearsal | Required outcome under the intended policy |
|---|---|
| Describe a report through the intent helper | Description is produced; action block is skipped |
| Write directly into the project | Write is denied |
| Delete a project file | Deletion is denied |
| Contact an external service | Connection cannot reach that service |
| Start with required isolation unavailable | Script does not execute |
This is a test specification, not a transcript of results. Each row needs an executable test against the runtime and kernel versions being supported.
For filesystem tests, check the files afterward. For network tests, check the receiving side too. “The script printed an error” is weaker evidence than “the prohibited effect did not occur.”
Intent wrappers give us readable plans. Adversarial tests give us evidence about enforcement.
A blocked write is not a simulated write
Suppose a script does this:
- Create a directory.
- Write a file inside it.
- Read that file to calculate a checksum.
- Upload the checksum.
Skipping the first two steps doesn’t let the third step proceed as usual. Denying the writes doesn’t help either.
We now have a choice:
- Stop at the first operation that requires a missing result.
- Supply synthetic results or fixtures.
- Execute against a disposable workspace.
- Restructure the tool to build a plan before applying it.
Each approach can be useful. None is a universal, transparent simulation of the live system.
Fixtures may be stale. A disposable workspace may differ from the real destination. A plan may become invalid between inspection and execution. Permissions, disk space, remote state, and concurrent changes can all differ on the real run.
Even a perfectly confined rehearsal cannot promise that tomorrow’s live execution will succeed—or take exactly the same path.
Safety and fidelity are separate properties. We can make the rehearsal safer without pretending it is a prediction of the future.
Not every dry run needs to prohibit every effect
Printing the plan is itself an effect. A tool might also reasonably write a rehearsal log or use a temporary directory.
So “no side effects” is often too vague to be useful. A more honest contract would be:
This mode may write into its disposable workspace and print a plan. It may not modify the project or contact external services.
That contract is narrower, but we can reason about it and test it.
It is also different from promising to safely execute arbitrary hostile code. Containing malicious code involves additional concerns, including resource exhaustion and the exposed kernel attack surface. Guardrails for a buggy maintenance script should not silently become a claim of complete hostile-code isolation.
Two layers, two responsibilities
The useful combination is not “a flag that makes everything safe.” It is a division of responsibility:
- The application describes the actions it understands.
- The operating system rejects actions outside the permitted boundary.
The application makes the rehearsal informative. The OS catches some of the mistakes the application failed to anticipate.
Neither layer replaces the other. A denied operation doesn’t explain the rest of the plan. A beautifully formatted plan doesn’t prove that no hidden write occurred.
This is the direction I want to take Rye’s dry-run support: explicit intent at the language level, specific restrictions at the OS level, and no quiet fallback from enforcement to wishful thinking.
A dry run is a promise. The useful next question is not just whether the code remembers that promise, but which parts of it we can make the code unable to break.