On this page

0087. Spawn programs without implicit shell fallback

Context

The macOS gate proves that executable text without a shebang can run through /bin/sh in both backends. Darwin's posix_spawnp performs this fallback after ENOEXEC; Rust 1.92 Command uses the same API. This violates ADR-0056's explicit no-implicit-shell contract even when the executable name is an absolute path.

Sources: Apple libc, Rust 1.92.

Decision

Native runtime launches with posix_spawn and performs PATH search explicitly. Names containing a slash launch directly. Empty PATH entries denote the current directory; absent PATH uses /usr/bin:/bin. Preserve original argv[0]. Continue on ENOENT/ENOTDIR, remember EACCES, and return other errors immediately, including ENOEXEC. Publish a child PID only after successful spawn. Preserve file actions, default child SIGPIPE, capture/stream descriptors, and kill/reap cleanup.

The macOS interpreter uses the safe subprocess 1.2.1 API with the same explicit PATH search and direct executable candidates. Keep the job while draining both capture streams and waiting; on an I/O/wait error kill and reap it before returning the original error. Capture stdin remains null; stream descriptors are inherited. The library resets SIGPIPE and clears the child signal mask. Signal-mask inheritance was not a language contract. Other hosts retain std::process::Command.

Dependency justification: macOS-only subprocess provides safe direct exec without implicit shell fallback or unsafe Rust in the compiler. Its Unix dependency is libc. Cargo.lock also records its conditional Windows dependencies. Library API and source.

Alternatives considered

Consequences

Both backends reject malformed executable files without shell effects and still support explicit shebang scripts or an explicitly requested /bin/sh -c. Error codes, raw output, empty arguments, capability checks, and nonzero child exit statuses retain their contract. No language syntax or diagnostics change. Keep absolute/PATH/empty-entry/permission/ENOEXEC regressions and sanitizer-backed process/owned-child cleanup checks. No compatibility or data migration is needed.