Skip to content

env

The env module reports basic process and host information: whether an environment variable is set, the current working directory, and the operating system name and CPU architecture.

use std::core::env

Check whether an environment variable is set.

if env::has("API_KEY") {
print("API key configured")
}

Get the absolute path of the current working directory.

let dir = env::cwd()
print(dir)

Get the operating-system name — typically "linux", "macos", or "windows".

let name = env::os()
print(name)

Get the CPU architecture — typically "x86_64" or "aarch64".

let arch = env::arch()
print(arch)
FunctionSignatureDescription
env::has(name)(string) -> boolVariable is set
env::cwd()() -> stringCurrent working directory
env::os()() -> stringOperating-system name
env::arch()() -> stringCPU architecture

Every env function requires the Env permission. In a sandboxed scope without Env, a call to env::has, env::cwd, env::os, or env::arch fails with a permission error rather than returning a value.