Environment variables

Spaces sets these variables for every process, terminal, and script that runs in a workspace, so your commands can find their port, URL, and directory without hardcoding them.

Workspace variables

VariableValue
SPACES_WORKSPACE_IDthe workspace's id
SPACES_PROJECT_IDthe project's id
SPACES_WORKSPACE_SLUGa DNS-safe slug, for example login-fix-a3f9c2d1847b (home-1a2b3c4d5e6f for the home workspace, ~)
SPACES_WORKSPACE_DIRthe workspace's directory
SPACES_PROJECT_DIRthe project's directory

Service variables

Each declared service gets three variables, named from the service with hyphens turned into underscores and uppercased, for example api-server becomes API_SERVER:

VariableValue
SPACES_<SERVICE>_PORTthe assigned local port
SPACES_<SERVICE>_HOST<service>.<slug>.localhost, no scheme or port
SPACES_<SERVICE>_URLhttp://<service>.<slug>.localhost:7391

See Services and URLs for how the port and URL are assigned and routed.

Terminal variables

SPACES_TERMINAL_TRACKING_ID identifies the terminal session a command is running in. Coding agents read it to report their own lifecycle with spaces agent signal.

Where they apply

The workspace and service variables are set for every process, every terminal, and the setup and stop scripts. SPACES_TERMINAL_TRACKING_ID is set only in terminal sessions, since the setup and stop scripts do not run inside a tracked terminal. A workspace's settings dialog has a read-only Environment section that lists the values a running process or terminal actually receives, see Workspaces.