Skip to content

Add server access to tasks and dev environments#4023

Open
peterschmidt85 wants to merge 3 commits into
masterfrom
codex/task-server-access
Open

Add server access to tasks and dev environments#4023
peterschmidt85 wants to merge 3 commits into
masterfrom
codex/task-server-access

Conversation

@peterschmidt85

Copy link
Copy Markdown
Contributor

Problem

Tasks and dev environments may need to call dstack themselves, for example to
inspect runs, submit another run, or attach to it. This currently requires the
dstack server to accept direct connections from the run.

UX

Add server: true to task and dev-environment configurations.

type: task
image: dstackai/dstack
server: true
env:
  - DSTACK_TOKEN
commands:
  - dstack ps

With server: true, dstack exposes the server managing the run through
/run/dstack/server.sock inside each job. It sets DSTACK_SERVER_URL to the
corresponding http+unix URL and DSTACK_PROJECT to the current project,
allowing the CLI and API clients to use that connection.

Authentication remains explicit. dstack does not inject DSTACK_TOKEN; it can
be passed through the existing environment or secret mechanisms.

The CLI also accepts DSTACK_SERVER_URL, DSTACK_PROJECT, and DSTACK_TOKEN
as a complete configuration without requiring ~/.dstack/config.yml.

server is not supported for services.

Implementation

Before starting commands, the server opens an SSH connection to each job and
creates a remote Unix-socket forward. Connections to
/run/dstack/server.sock inside the job are forwarded to the HTTP port of the
server managing the run. DSTACK_SERVER_URL points clients to this socket.

This uses the existing job SSH path, so the server does not need a public URL
or gateway. Health checks use the same socket path end to end; if the SSH
connection or socket becomes stale, the server closes and recreates the
tunnel. The tunnel is removed when the job terminates.

@peterschmidt85 peterschmidt85 requested a review from un-def July 11, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant