DocsConfigure Environments
v2.19+

Configure Environments

A sandbox runs inside the container image and environment you define for the workload. The most reproducible setup is to build dependencies into the image or apply them through organization presets.

This page continues from the Sandbox Quick Start. The Python examples reuse its sandbox client; the CLI examples reuse its quick-start project, sandbox/sandbox.yaml, and RUN_UUID variable.

Choose an Image

Start with an image that already has the tools required by your workflow. Override the image in the shared sandbox file when launching a new run:

polyaxon run -p quick-start -f sandbox/sandbox.yaml --image python:3.12

This keeps the file's workspace and access plugins. Use the new run UUID for subsequent commands.

For notebook workflows, use a notebook image. For GPU workflows, use an image with compatible CUDA, framework, and driver expectations.

Install Temporary Packages

Temporary installs are useful while debugging:

with sandbox.process.exec_stream(
    command=["pip", "install", "rich"],
) as events:
    for event in events:
        print(event)
polyaxon sandbox exec -p quick-start -uid $RUN_UUID --stream -- pip install rich

Promote repeated package changes into a Docker image or preset once the workflow stabilizes.

Set Environment Values

Add environment variables to sandbox/sandbox.yaml with the root env shortcut:

env:
  EDITOR: vim

For a single launch, pass the value inline:

polyaxon run -p quick-start -f sandbox/sandbox.yaml --env EDITOR=vim

Both options set the value when creating a new run; they do not change an existing sandbox.

For temporary values in an interactive shell:

polyaxon ops shell -p quick-start -uid $RUN_UUID
export EDITOR=vim
export DEBUG=1

These values belong to that shell. With plugins.tmux enabled, they remain available when you detach and reconnect to the same session. They disappear when the shell exits, the pod restarts, or the run stops, and they do not affect separate polyaxon sandbox exec commands. Use the root env shortcut for values that every process needs or that should be reproducible.

For a value needed by one command, pass it through the process API or prefix the CLI's remote command with env:

result = sandbox.process.exec(
    command=["printenv", "EDITOR"],
    env={"EDITOR": "vim"},
)
print(result.stdout, end="")
polyaxon sandbox exec \
  -p quick-start \
  -uid $RUN_UUID \
  -- env EDITOR=vim printenv EDITOR

polyaxon sandbox exec has no --env option. In both examples, the value is available only to that command and its child processes.

Use the Polyaxonfile environment specification for pod settings such as node selectors, service accounts, security contexts, and DNS. Presets can supply these settings.

Use Presets

Presets let platform teams provide reusable defaults for queues, resources, connections, security, and environment settings:

from polyaxon.client import RunClient

preset_client = RunClient(project="quick-start")
preset_run = preset_client.create_from_polyaxonfile(
    polyaxonfile="sandbox/sandbox.yaml",
    presets=["dev-sandbox"],
    approved=True,
)
print(preset_run.uuid)
polyaxon run -p quick-start -f sandbox/sandbox.yaml --presets dev-sandbox

Both examples start a new service. Python returns its UUID as preset_run.uuid; for later CLI commands, replace the current value of RUN_UUID with the new run UUID.

See scheduling presets for details. The Python interfaces are documented in the run client and process references.