Summary
Issue #4384 highlights a recurring problem: users need a safe, standard way to run local scripts and applications with azd environment values available, without leaking those values into the parent shell or relying on language-specific loaders.
This issue proposes a first-class azd command to run an arbitrary child process with the selected azd environment loaded into that process only.
This is proposed as an alternative to PR #7364, which adds --export to azd env get-values for shell sourcing. Instead of making shell export the primary mechanism, this proposal focuses on direct process execution for scripting scenarios that already have wide usage today.
Working name:
azd env exec <command> [args...]
Examples:
azd env exec python script.py
azd env exec uv run app.py
azd env exec npm run dev
azd env exec -e myenv ./write-env.sh
# for passing flags to the script, `--` is required
azd env exec -- python script.py --port 8000 --reload
azd env exec -e myenv -- docker compose up --build
This issue is about the behavior and user experience, not the final command name. The basic form should be azd env exec python script.py, and the command should also support -- so users can cleanly pass flags through to the child process when needed.
What
We should add a command that:
- Resolves the current azd environment, or a specific one via
--environment
- Loads azd environment values into a child process
- Runs the requested command directly, preserving
stdin, stdout, and stderr
- Returns the child process exit code
- Does not mutate the caller's shell or parent process environment
At a high level, this should let users and tools say "run this program with the active azd environment" without having to manually export variables, source shell fragments, or write language-specific environment loaders.
Why
Today, users typically have to choose between a few imperfect options:
- Put the command behind a hook and run it via
azd or azd hooks run
- Export azd variables into the current shell
- Load the azd
.env file inside the app with language-specific code
Each workaround has drawbacks:
- Hooks are useful, but they require command definitions in
azure.yaml and make azd the entry point for running the app or script
- Exporting values into the current shell is shell-specific, easy to misuse, and can leave behind stale variables that taint later commands
- Language-specific loaders create extra per-language guidance and complexity for templates and samples
This directly addresses the underlying issue described in #4384 by giving users a standard, shell-agnostic way to run scripts with azd env loaded, while avoiding the parent-shell tainting and export-driven confusion called out in that issue.
There is also a tooling and automation benefit here: azd env exec python script.py is much easier for agents, scripts, and task runners to invoke safely than a pattern based on eval, source, or shell-generated export output.
Scoping
In scope for this issue:
- Running an explicit command with azd env loaded
- Supporting
--environment
- Child-process-only environment behavior
- Exit code passthrough
- Interactive command support when the child process needs a TTY
Out of scope for this issue:
- Auto-exporting to
.env files
- Merging or syncing variables into app-specific config files
- Persisting env vars in the user's current shell
- A full azd SDK/library story for each language
- Secret-resolution enhancements beyond whatever the current azd environment-loading model already supports
- A more targeted service-simulation experience for running an azd service locally
Open questions
- Should this live under
azd env exec, azd shell, or another name?
- Should the initial issue only support explicit commands, or also support "no args" interactive shell launching later?
- Do we want to support any extra filtering or service-scoped behavior now, or keep v1 strictly to "selected azd env as-is"?
Future direction
Longer term, we may want a higher-level command such as azd run that provides a more targeted development experience, potentially simulating how a service runs within azd and layering in service-specific behavior.
That should be treated as a future direction, not a prerequisite for this issue.
This issue is intentionally focused on the lower-level scripting capability that has broad usage today: run an arbitrary command with azd env loaded.
Why this is worth doing first
This is the smallest first-class feature that closes the biggest gap:
If we later add a separate export/sync feature, the two can complement each other:
env exec for "run a process safely"
env export / sync for "write selected values to a file"
Summary
Issue #4384 highlights a recurring problem: users need a safe, standard way to run local scripts and applications with azd environment values available, without leaking those values into the parent shell or relying on language-specific loaders.
This issue proposes a first-class
azdcommand to run an arbitrary child process with the selected azd environment loaded into that process only.This is proposed as an alternative to PR #7364, which adds
--exporttoazd env get-valuesfor shell sourcing. Instead of making shell export the primary mechanism, this proposal focuses on direct process execution for scripting scenarios that already have wide usage today.Working name:
Examples:
This issue is about the behavior and user experience, not the final command name. The basic form should be
azd env exec python script.py, and the command should also support--so users can cleanly pass flags through to the child process when needed.What
We should add a command that:
--environmentstdin,stdout, andstderrAt a high level, this should let users and tools say "run this program with the active azd environment" without having to manually export variables, source shell fragments, or write language-specific environment loaders.
Why
Today, users typically have to choose between a few imperfect options:
azdorazd hooks run.envfile inside the app with language-specific codeEach workaround has drawbacks:
azure.yamland makeazdthe entry point for running the app or scriptThis directly addresses the underlying issue described in #4384 by giving users a standard, shell-agnostic way to run scripts with azd env loaded, while avoiding the parent-shell tainting and export-driven confusion called out in that issue.
There is also a tooling and automation benefit here:
azd env exec python script.pyis much easier for agents, scripts, and task runners to invoke safely than a pattern based oneval,source, or shell-generated export output.Scoping
In scope for this issue:
--environmentOut of scope for this issue:
.envfilesOpen questions
azd env exec,azd shell, or another name?Future direction
Longer term, we may want a higher-level command such as
azd runthat provides a more targeted development experience, potentially simulating how a service runs within azd and layering in service-specific behavior.That should be treated as a future direction, not a prerequisite for this issue.
This issue is intentionally focused on the lower-level scripting capability that has broad usage today: run an arbitrary command with azd env loaded.
Why this is worth doing first
This is the smallest first-class feature that closes the biggest gap:
evalgenerated shell exportsIf we later add a separate export/sync feature, the two can complement each other:
env execfor "run a process safely"env export/ sync for "write selected values to a file"