description: "An immutable snapshot of this run's environment that remembers which layer supplied each value, for packages that must resolve user-facing values without trusting a flattened process.env."
English | 中文
dsh-launch-environment freezes this run's environment at launch into an immutable snapshot that records which layer supplied each value. Resolving a name searches the layers from most to least trusted — the inherited process environment, the invoking directory's .env, then the Harness home's .env — so the winning value always carries its source. A caller can also resolve from a named subset of layers, which is a refusal rather than a demotion: omitted layers are unreachable no matter how trust ordering changes later. Values still reach process.env for config expressions and third-party libraries, but nothing the harness resolves treats that flattened view as authoritative. It is a zero-dependency library that product packages import directly; a cordis.yml cannot load it.
Resolve user-facing values through the snapshot instead of process.env whenever the layers are not equally trusted — for example a credential override a caller must never take from a project directory.
import { launchEnvironmentOf } from '@deepseek-ai/dsh-launch-environment'
declare const ctx: import('@deepseek-ai/cordis').Context
const endpoint = launchEnvironmentOf(ctx).get('DEEPSEEK_BASE_URL')?.value
get(name) searches every layer, most trusted first. getFrom(name, sources) searches only the named layers without changing that trust order — a caller that must never accept a layer leaves it out of the list, so no future reordering can let it back in.
| Layer | What it is |
|---|---|
| Inherited process environment | What the launching shell, CI job, or container passed in — this run's explicit intent |
<invocation cwd>/.env |
The project the harness was launched in, which the product trusts to configure its own agent |
$DSH_HOME/.env |
The user's own machine-level defaults |
Names match the way the platform matches them: exactly on POSIX, case-insensitively on Windows. A case-sensitive lookup on Windows would rank the wrong layer — a shell's deepseek_api_key and a project .env's DEEPSEEK_API_KEY are one variable to the OS.
launchEnvironmentOf(ctx) returns the launcher's snapshot when the product CLI booted the tree, and otherwise the inherited environment as the only layer. The fallback does not weaken the rules: an SDK host or a bare cordis.yml discovered no files, so everything it has is the environment it was launched with.
Read these pages when you need the launcher that builds the snapshot or the consumers that resolve through it.
ctx.launchEnvironment before any config entry mounts.These limits define when the snapshot is not a security boundary. They are current package constraints, not a task backlog.
process.env, so ordinary project variables reach child processes under dsh-subprocess's scrub; the product launcher's .env contract rejects bootstrap variables before materialization.