env(key) reads one environment variable as a string. Locally it resolves from your shell environment merged with the project’s .env file; in a deployed agent it resolves from the environment’s variable store that you manage with lua env. Available everywhere agent code runs, including workflow code steps, where ctx.env[key] reads the same values; process.env.KEY works too.
Verified against lua-cli 3.33.0.
Quick example
Treat a missing secret as a configuration error.Functions
env(key, options?)
Returns the variable’s value, orundefined when it isn’t set.
string
required
The variable name, for example
WEATHER_API_KEY.boolean
Accepted for compatibility; the function ignores it.
Values are always strings; convert numbers and booleans yourself.
Returns — the value, or
undefined.
Example
undefined.
env.template(key)
Returns a placeholder that a workflow definition resolves from the target agent’s environment atlua push, wherever a template(...) binding is accepted.
string
required
The variable name. Names ending in
SECRET, TOKEN, KEY, or PASSWORD are refused.{ __envRef: key }. It is never a value: read the variable with env(key) inside the step that needs it.
Example
env-template-secret-key: \API_KEY` looks like a secret — read it with env(‘API_KEY’) inside execute instead` for a secret-looking name.
env.template belongs in workflow files, which the compiler evaluates. In a deployed agent the runtime env has no template member (env.template is not a function), and in lua test it returns the placeholder without the secret-name check.Types
string | { base?: string; voice?: string; text?: string }
See also
lua env— set, list, and delete variables per environment- About environments — sandbox and production, and what each shares
- Call your API — keep credentials out of code with
env - Workflow builder — where
env.templatebindings are accepted

