Module
std.env — the program's arguments and the host's environment variables. Stability tier: core.
This is the module that lets a project stop holding its input as data. Until argv arrives, every program in a corpus is a literal with a main around it; args() is the seam where a real one starts.
**Capability: env (I13).** Every function here except the two pure entry helpers reaches the host's process context, is tagged env in the toolchain's sandbox table, and is categorically refused at comptime (D33) for the reason the table gives: *determinism and confinement — environment contents differ per machine and may hold secrets*. The refusal is E0701; tests/env/comptime_refuses.lu holds it one level down at the builtin, because a comptime fn cannot call across a module boundary at this pin (F-0051).
entry_key and entry_value are PURE and comptime-safe — they cut a K=V line and touch nothing. §14 says to state that exception explicitly, because in a capability module the pure function is the surprising one.
Errors are rows and the vocabulary is the toolchain's, verbatim (§14): missing for a variable the host does not have, utf8 for a value the host holds in an encoding this machine cannot decode, and invalid for a NAME the platform cannot store. std adds no translation layer, no error type of its own, and no coarsening a caller did not ask for. Nothing here traps: a host that does not have a variable is not a caller contract violation.
missing joins §2's absence family — "there is nothing here" — while invalid is an error mark: it names an argument the CALLER got wrong (an empty name, or one containing = or NUL), and it is a row rather than a trap only because the platforms disagree about which names they will hold, so a caller cannot portably check in advance.
The arguments are the program's, not the runtime's. args() is what the user typed after the program name — it does not include the executable path, and it does not include the toolchain's own flags. Under wolf conform-run and lupin conform-run there are NO arguments on any lane, by design (the checked machine mirrors the stdin posture and the native rung runs the binary bare), so args().len is 0 in every test in this repository and in every doc example below. wolf run file.lu a b c is where real arguments arrive. A test that asserted a specific argument would be asserting the rig, not the language.
**The invocation name and the byte arguments: arg0 and args_bytes (sc75, wolf-std#98; s261, [os.env.argv], wolf 0.2.36).** arg0() is argv[0] exactly as the program was invoked — a bare PATH name, an absolute path, ./prog, a symlink's own name, the name a shell's exec -a chose — and not the resolved executable, which is the reviewed program() below. args_bytes() is every argument as bytes, the name first (argv[0], then argv[1..]), verbatim on unix and WTF-8 on windows, so a program can read an argument that is not text. The checked machine takes its argv from conform-run --checked --argv-hex=HEX, repeated, the first occurrence argv[0] ([exec.checked.argv]; without it the argv is empty, so arg0() is empty text); wolf run --checked is a native build, not that machine.
The text trap. args(), arg(i) and arg0() read text, and a wolf str is UTF-8 by definition, so an argument they read that is not UTF-8 is not a row and not a lossy decode: the program traps argument-utf8 ([conf.trap.set]; exit 134 at the native process boundary), with the message argument N is not UTF-8; read it with env_args_bytes(), N the OS argv index (the name is 0). args() and arg(i) never decode the name and arg0() decodes nothing else, so a program that may be handed bytes reads args_bytes() and decodes what it wants with str_from_utf8, which answers its utf8 row instead.
**set writes, and what it writes to is not the same place on every lane.** The checked machine keeps a machine-local overlay; the native rung writes the real process environment. The same program observes the same answers either way — which is exactly what makes a round trip (set then get) the honest test — but a value set here is not visible to a child process on the checked lane, and std.process does not exist yet to notice.
**The working directory: cwd and set_cwd (s215).** cwd was a reviewed contract here because the builtin tier had a READ (os_cwd) and no WRITE, and a module that shipped the one without the other would have decided by accident what a directory change is (F-0067). wolf-lang s215 added os_chdir, so the pair lands together. cwd is a query about this program's situation exactly as args and vars are, and carries their env capability. set_cwd ACTS — it moves the directory every later relative path and every child starts in — and its capability is env too, as set's is: ruling #54 (2026-10-07) charges os_chdir to env, the process context it changes, and not to io, which this doc said until the pin carried the ruling (wolf 0.2.26, ctfe::intrinsics::host_stub). Under s217 a package that reaches set_cwd declares env; both are refused at comptime. The directory is the PROCESS's, shared by every task: a program that changes it while another task resolves a relative path races itself. The checked machine keeps a machine-local directory ([os.fs.chdir]), for the reason it keeps set's overlay, and every relation a program can observe is the same there.
**This process's ids: pid and ppid (s232).** They are queries about this program's situation as cwd is, and charge env as it does (ruling #70 R8). They live here and not in std.process, whose pid is a child's.
**Who this process runs as: uid, euid, gid, egid, groups (s236).** The same kind of question as pid — about this process, read and nothing started — and here for ruling #74's reason: this process's own ids live in std.env. They charge env. Changing them is std.process.set_ids, which charges exec; the names behind the numbers are in the account files, which std.os.users reads.
Lanes. The checked tier and the native rung both execute the env_* builtins; lupin 0.1.6 has none of them and refuses at resolve. It resolves module bodies LAZILY, so a program that touches only entry_key/entry_value runs there — which is why tests/env/entry_helpers.lu has three lanes and the rest have two.
Reviewed contracts, blocked or unscheduled:
pairs() -> List[(str, str)]
`vars()` already split. Blocked by the language: `List[(str,
str)]` is `unsupported` in wolfc (F-0026's tuple-element gap),
which is why the split ships as two pure functions over one line
instead of as a shape.
program() -> str
The executable's own path. Not in the builtin tier — `env_args`
is the arguments only — and inventing it from `args()` would
hand back the first argument, which is a different thing. Nor is
it `arg0()` (sc75), which is the name the invoker USED: a symlink
or `exec -a` makes the two differ. The resolved path is
`os_exe`'s answer, and a wrapper over it is its own ruling.
Functions and methods
fn · Source line 149
pub fn cwd() -> str ! {io}
The process's working directory: the directory every relative path resolves against and every child starts in.
Rows: io when the host cannot answer — the directory was removed from under the process, or its path is not text this str tier can hold. Never traps. The answer is the host's canonical one (what getcwd reports), so after set_cwd("a/..") it names the directory itself, not the spelling.
Capability env; refused at comptime (D33). Delegates to os_cwd.
(env.cwd() else "").len > 0
fn · Source line 176
pub fn set_cwd(path: str) -> () ! {not_found, denied, io}
Make path the process's working directory. A relative path resolves against the current one.
Rows: not_found when nothing is at path; denied when the host will not let this process enter it; io when path names something that is not a directory (the host's ENOTDIR, which has no tag of its own), and for every other host failure. Never traps; a failed change leaves the directory where it was.
From the call on, every relative path an fs call takes resolves against the new directory, cwd() answers it, and a child std.process starts begins in it. This is a shell's cd: it changes the program, not one command, so a library that needs a child in another directory should not move its caller's.
Capability env (ruling #54), as set's; refused at comptime (D33). Delegates to os_chdir (wolf-lang s215, [os.fs.chdir]).
let here = env.cwd()?
env.set_cwd(".")?
(env.cwd() else "") == here
fn · Source line 209
pub fn umask(mask: int) -> int ! {invalid, unsupported}
Set the process's file mode creation mask to mask, and answer the mask it replaced.
[os.fs.umask] (wolf-lang#704): umask. The mask is the set of permission bits a creation does NOT get — every file and directory this process creates has the mode its creation asked for less the mask. Set-and-answer is the only form any host has, so READING the mask is two calls: let m = env.umask(0o022)? then env.umask(m)?.
The mask is the PROCESS's: every task's, and every child's at its spawn (a shell's umask is this call). A program that changes it while another task creates a file races itself — the two-call read included — so set it where a C program does, before starting tasks. fs.set_mode after a creation reaches a mode the mask would have taken.
Rows: invalid when mask is outside 0..=0o777 (nothing changes); unsupported on a host with no mask (windows, by name). Never traps. Unlike set_cwd and set, the checked machine sets the REAL mask ([os.fs.umask] says why); lupin has no host call for it and declines by name.
Capability env (ruling #54's reading, as set_cwd's); refused at comptime (D33). Delegates to os_umask.
let old = env.umask(0o1000) else |_| 0 - 1
old == 0 - 1
fn · Source line 228
pub fn pid() -> int
**s232 ([os.proc.self]): this process's id** — a shell's $$, and what a pid file holds. std.process.pid is a CHILD's id, by its handle; this is the caller's own.
Total: every host has one, so there is no row. Never traps. On the checked machine and on lupin it is the id of the process the program runs as (the wolf or lupin process).
Capability env (ruling #70 R8: a read of process context); refused at comptime (D33). Delegates to os_pid.
env.pid() > 0
env.pid() == env.pid()
fn · Source line 247
pub fn ppid() -> int ! {unsupported}
**s232 ([os.proc.self]): the id of this process's parent, NOW** — a shell's $PPID. A process whose parent has ended answers the id of whichever process adopted it, so a program that wants the parent it was started by reads this once, at start.
Rows: unsupported on a host with no such call (windows, by name). Never traps.
Capability env (ruling #70 R8); refused at comptime (D33). Delegates to os_ppid.
let parent = env.ppid() else |_| 1
parent > 0
fn · Source line 262
pub fn uid() -> int ! {unsupported}
**s236 ([os.proc.ids]): this process's REAL user id** — who started it (getuid). It differs from euid only in a program started set-user-id.
Rows: unsupported on a host with no user ids (windows, by name). Never traps. lupin declines by name (it has no host call for an id), so the example is prose: env.uid()? == env.euid()? holds in every program that was not started set-user-id.
Capability env (ruling #74's reading of pid); refused at comptime (D33). Delegates to os_uid.
fn · Source line 278
pub fn euid() -> int ! {unsupported}
**s236 ([os.proc.ids]): this process's EFFECTIVE user id** — the one the host checks when the process opens a file, signals another process or changes an owner (geteuid). 0 is the super-user, so "am I root?" is env.euid()? == 0. A file this process creates is owned by this id.
Rows: unsupported on a host with no user ids (windows, by name). Never traps. lupin declines by name, so the example is prose: a server told to drop privilege asks env.euid()? == 0 first and warns instead when it is not.
Capability env; refused at comptime (D33). Delegates to os_euid.
fn · Source line 289
pub fn gid() -> int ! {unsupported}
**s236 ([os.proc.ids]): this process's real group id** (getgid).
Rows: unsupported on a host with no group ids (windows, by name). Never traps. lupin declines by name; the example is prose, as uid's.
Capability env; refused at comptime (D33). Delegates to os_gid.
fn · Source line 301
pub fn egid() -> int ! {unsupported}
**s236 ([os.proc.ids]): this process's effective group id** (getegid) — the group a file it creates is given on most hosts.
Rows: unsupported on a host with no group ids (windows, by name). Never traps. lupin declines by name; the example is prose, as uid's.
Capability env; refused at comptime (D33). Delegates to os_egid.
fn · Source line 322
pub fn groups() -> List[int] ! {io, unsupported}
**s236 ([os.proc.ids]): this process's SUPPLEMENTARY groups** — the other groups the host counts it a member of, exactly as the host lists them (getgroups), in the host's order.
Whether the effective group is in the list is the host's: linux lists it only if the list was set so, macOS puts it first. A program that wants every group it is in — what id -G prints — takes egid() first and then this list, dropping a repeat. On macOS the list is what getgroups(2) answers there: at most sixteen, and not the directory service's whole membership.
Rows: unsupported on a host with no group ids (windows, by name); io when the host will not answer. Never traps. lupin declines by name; the example is prose: for g in env.groups()? { … }.
Capability env; refused at comptime (D33). Delegates to os_groups.
fn · Source line 340
pub fn args() -> List[str]
The program's arguments, in the order the user gave them.
Total: no rows. One trap, the host's and not a contract: an argument that is not UTF-8 traps argument-utf8 (the module header's "text trap"; args_bytes() reads it). Excludes the executable's own path and the invocation name (see the module header). The list is freshly allocated in the ambient region on every call; nothing here is cached, because a cache would be a promise the host has not made.
Capability env; refused at comptime (D33). Delegates to env_args.
env.args().len >= 0
fn · Source line 361
pub fn arg(i: int) -> str ! {none}
The argument at i, counting from zero.
Rows: none when i is negative or past the last argument — an absence and not a trap, because an index into argv is DATA the program received rather than a bound the caller could have checked (§8's rule, in the place it matters most: the index usually comes from the program's own option parser).
Traps argument-utf8 when an argument is not UTF-8, as args() does: it reads the same list.
Capability env; refused at comptime (D33). Delegates to env_args.
(env.arg(0) else "<none>") == "<none>"
(env.arg(-1) else "<none>") == "<none>"
fn · Source line 394
pub fn arg0() -> str
The name this program was invoked by: argv[0], exactly as the invoker spelled it (a bare PATH name, an absolute path, ./prog, a symlink's own name, exec -a NAME's NAME). Not the resolved executable: a symlink and exec -a make the two differ.
Total: no rows. Empty text when the invoker passed no argv[0], and on the checked machine run without --argv-hex. One trap, the host's: a name that is not UTF-8 traps argument-utf8 (the module header's "text trap"), and args_bytes()[0] holds it as bytes. It decodes the name alone; a non-UTF-8 argument after it does not trap here.
The answer is materialized in the ambient region, freshly on every call (env_arg0 is a [mem.region.escape] site, as os_cwd is).
Capability env; refused at comptime (D33). Delegates to env_arg0 (s261, [os.env.argv]). lupin resolves the builtin from 0.1.59 (wolf-interp#295).
let raw = env.args_bytes()
raw.len == 0 || raw[0].len == env.arg0().len
fn · Source line 420
pub fn args_bytes() -> List[List[byte]]
Every argument as bytes, the invocation name first: argv[0], then argv[1..] in order — so args_bytes().len is args().len + 1 whenever the invoker passed a name. No decoding, no entry left out, no terminating NUL: verbatim bytes on unix, WTF-8 for windows' UTF-16 arguments (the encoding fs uses for the OS's names).
Total: no rows, no traps. It is the reader for an argument that is not text; str_from_utf8 on one entry answers its utf8 row where args() would trap. Empty when the invoker passed no argv at all, and on the checked machine run without --argv-hex.
The list and its entries are materialized in the ambient region, freshly on every call.
Capability env; refused at comptime (D33). Delegates to env_args_bytes (s261, [os.env.argv]). lupin resolves the builtin from 0.1.59 (wolf-interp#295).
let raw = env.args_bytes()
raw.len == 0 || raw.len == env.args().len + 1
fn · Source line 445
pub fn get(name: str) -> str ! {missing, utf8}
The value of the environment variable name.
Rows: missing when the host has no such variable, utf8 when it has one whose value is not well-formed UTF-8 (a wolf str is UTF-8 by definition, so a value that cannot decode is a miss and never a lossy read). Never traps.
An empty value is a VALUE: get of a variable set to "" answers "" and not missing. That distinction is the whole reason this returns a row instead of a string.
Bare get is the checked-access spelling and this one can miss (§1), so the name is right and the row is not decoration.
Capability env; refused at comptime (D33). Delegates to env_get.
env.set("WOLF_STD_DOC_GET", "wolf")?
(env.get("WOLF_STD_DOC_GET") else "?") == "wolf"
(env.get("WOLF_STD_DOC_ABSENT") else "?") == "?"
fn · Source line 464
pub fn has(name: str) -> bool
Whether get(name) would answer with a value.
Total: no rows, no traps. false for a variable the host does not have AND for one whose value this machine cannot decode — the two are deliberately one answer, because the question this predicate asks is "can I read it", and a caller who needs to tell the cases apart calls get and handles the tags.
Capability env; refused at comptime (D33). Delegates to env_get.
env.set("WOLF_STD_DOC_HAS", "1")?
env.has("WOLF_STD_DOC_HAS") == true
env.has("WOLF_STD_DOC_NOT_SET") == false
fn · Source line 487
pub fn vars() -> List[str]
Every environment variable the host has, as K=V lines sorted by name.
Total: no rows, no traps. The sort is the builtin tier's and it is a DETERMINISM promise, not a convenience: two runs of one program see the same order, and a program that prints its environment produces a diffable output. Cut a line with entry_key and entry_value.
A variable whose value the host holds in a non-UTF-8 encoding is omitted rather than mangled — the same posture get's utf8 row takes, in a function that has no row to say it with.
Capability env; refused at comptime (D33). Delegates to env_vars.
env.set("WOLF_STD_DOC_VARS", "x")?
env.vars().len > 0
fn · Source line 509
pub fn set(name: str, value: str) -> () ! {invalid}
Set the environment variable name to value for this process.
Rows: invalid when the platform cannot hold the name — empty, or containing = or a NUL. Never traps: which names a platform accepts differs between hosts, so a caller could not portably have checked (§2's trap rule).
Setting is process-global and is not undone at any scope exit; a test that sets a variable is writing to the program it runs in. Use names nobody else will (WOLF_STD_…), which is what this repository's own tests and examples do.
Capability env; refused at comptime (D33). Delegates to env_set.
env.set("WOLF_STD_DOC_SET", "value")?
(env.get("WOLF_STD_DOC_SET") else "?") == "value"
fn · Source line 537
pub fn unset(name: str) -> () ! {invalid}
Remove name from this process's environment.
After it, get answers missing, has is false, vars() does not list the name, and a child started afterwards does not receive it. Removing a variable that is not there is not an error — the outcome the caller asked for already holds (POSIX unsetenv). This is NOT set(name, ""): an empty value is a value, and has answers true for it; that difference is why std shipped no unset until the builtin existed (wolf-lang#534, s225).
Rows: invalid for a name set would refuse — empty, or containing = or a NUL. Never traps.
Removing, like setting, is process-global and is not undone at any scope exit.
Capability env; refused at comptime (D33). Delegates to env_unset (wolf-lang s225, [os.env.unset]).
env.set("WOLF_STD_DOC_UNSET", "value")?
env.unset("WOLF_STD_DOC_UNSET")?
env.has("WOLF_STD_DOC_UNSET") == false
fn · Source line 557
pub fn entry_key(entry: str) -> str
The name half of a K=V line from vars().
Total: no rows, no traps, and PURE — comptime-safe, reaching no host. A line with no = at all is all name and no value, which is what a caller wants for the degenerate case: entry_key("BARE") is "BARE".
The cut is at the FIRST =, because a value may contain one and a name may not (that is exactly what set's invalid row is about).
env.entry_key("HOME=/home/wolf") == "HOME"
env.entry_key("EMPTY=") == "EMPTY"
env.entry_key("BARE") == "BARE"
env.entry_key("A=b=c") == "A"
fn · Source line 577
pub fn entry_value(entry: str) -> str
The value half of a K=V line from vars().
Total: no rows, no traps, and PURE — comptime-safe, reaching no host. A line with no = has an empty value. Everything after the first = is the value, = signs included.
env.entry_value("HOME=/home/wolf") == "/home/wolf"
env.entry_value("EMPTY=") == ""
env.entry_value("BARE") == ""
env.entry_value("A=b=c") == "b=c"