Automation often needs one command from a Conda environment without turning the whole shell, cron job, or CI step into an activated session. conda run starts that child process with the selected environment's paths and variables, then returns control to the same parent shell.
Conda can target an environment by name with -n or by full prefix path with -p. The command after the environment selector is the executable to run, and a -- separator keeps executable options from being read as conda run options.
Use --cwd when the child process must start from a project directory, and use --live-stream or --no-capture-output when logs should appear as the command runs. The target environment must already exist; create or repair it separately if conda run reports that the environment cannot be found.
Related: How to create a Conda environment
Related: How to activate a Conda environment
Related: How to initialize Conda for a shell
$ conda env list # conda environments: # # * -> active # + -> frozen base /opt/conda analytics /opt/conda/envs/analytics
The example uses an environment named analytics. Use the exact name from your own environment list, or use -p with a full prefix path when names are ambiguous.
$ echo "${CONDA_DEFAULT_ENV:-not active}" not active
This shell variable is only a quick before-and-after marker. An already activated shell should show the same value again after conda run exits.
$ conda run -n analytics python -c "print(__import__('sys').executable)" /opt/conda/envs/analytics/bin/python
The executable path should point inside the selected environment, not the parent shell's Python path.
$ conda run -n analytics -- python -V Python 3.13.14
The separator is useful when the command after conda run has its own flags or when a script generator builds the command line from separate pieces.
$ conda run -n analytics --cwd /srv/analytics python -c "from pathlib import Path; print(Path.cwd())" /srv/analytics
Replace /srv/analytics with the project or job directory that the command expects.
$ conda run --live-stream -n analytics python -c "print(*range(2), sep=chr(10))" 0 1
--live-stream and --no-capture-output both disable Conda's stdout and stderr capture for the child process.
$ echo "${CONDA_DEFAULT_ENV:-not active}" not active
If the value changed, another shell command changed the session; conda run itself exits after the child process and does not leave the selected environment activated.