env-var-conventions
Environment Variables — Conventions
Apply this skill when adding, renaming, or reviewing any sglang-owned environment variable (SGLANG_*, or a legacy SGL_* alias being phased out), or when touching python/sglang/srt/environ.py.
Rule 1 — Define in the Envs class in python/sglang/srt/environ.py
All sglang-owned env vars live as EnvField descriptors on the Envs class. Never add a new os.getenv("SGLANG_..."), get_bool_env_var("SGLANG_..."), or get_int_env_var("SGLANG_...") call site — the helpers in python/sglang/srt/utils/common.py carry an explicit FIXME: move your environment variable to sglang.srt.environ and exist only for pre-existing call sites.
Group the new entry under an existing section comment (e.g. # Logging Options, # Scheduler: recv interval, # Flashinfer). Add a new section comment only when none fits — never drop a new entry at the bottom of an unrelated block.
Decision table: register in Envs or use os.getenv?
| Variable | Owner | Goes through Envs? |
|---|---|---|
SGLANG_* |
sglang | Always. The canonical prefix for all new entries. |
MOONCAKE_*, ASCEND_*, DEEP_NORMAL_*, IS_H200, USE_TRITON_W8A8_FP8_KERNEL, HF_HUB_DISABLE_XET, DISABLE_OPENAPI_DOC |
Upstream/vendor alias that sglang wants to centralize | Yes — register in Envs so .get() / .override() work uniformly. Keep the upstream prefix. |
CUDA_*, NCCL_*, TORCH_*, OMP_*, HF_HUB_* (raw upstream) |
External tooling | No. Read with os.getenv — they're set by the launcher / driver, not by sglang. |
RANK, LOCAL_RANK, WORLD_SIZE, MASTER_ADDR, MASTER_PORT, HOME, PATH |
Distributed launcher / OS | No. os.getenv only. |
Test runner internals (PYTEST_CURRENT_TEST, etc.) |
Test framework | No. os.getenv only. |