Linkspan turns a Slurm job into servers you can reach from your laptop.
- Jupyter IDE. A Jupyter server in a folder of the job, in a Python environment Linkspan builds.
- VS Code IDE. An SSH server for one public key, for VS Code Remote-SSH.
- Usage. The job's CPU, GPU and memory use.
- Terminals. A PTY inside the job, in a browser tab.
- Filesystem (WIP). Datasets mounted or synced into the job.
- Pause/Resume (WIP). A
shell.execcommand paused by itsrefand resumed, in this job or a later one. - Workflows (WIP). Steps run at set points in the job's life, from a file.
Compute nodes accept no connections from off the cluster. To get through, Linkspan dials out over one of two transports: the link, a WebSocket to cs-plane, or a Dev Tunnel, made by whoever starts Linkspan, which Linkspan hosts from inside the job. Most people reach Linkspan through cs-bridge, the VS Code extension, or cs-jupyter, the JupyterLite distribution, both driving cs-plane. This document covers running Linkspan yourself.
curl -fsSL https://github.com/cyber-shuttle/linkspan/releases/latest/download/linkspan_Linux_x86_64.tar.gz |
tar -xz linkspanArchives exist for Linux and Darwin on x86_64 and arm64. To build from source, see
CONTRIBUTING.md.
| Feature | Needs |
|---|---|
| Everything | A writable home directory; Linkspan fetches and builds only under ~/.cybershuttle/ |
| Usage | Linux, cgroup v2 as Slurm lays it out; macOS builds report none |
| GPU usage | The NVIDIA driver; DCGM metrics also need libdcgm.so.4 and its host engine on 127.0.0.1:5555 |
--tunnel-mode=devtunnel |
HTTPS to tunnelsassetsprod.blob.core.windows.net, devtunnels.ms and rel.tunnels.api.visualstudio.com |
| Jupyter | curl on PATH; HTTPS to astral.sh, github.com, release-assets.githubusercontent.com and pypi.org |
| Terminals | Linux; HTTPS to github.com and release-assets.githubusercontent.com |
| Pause/Resume | criu on PATH, allowed to run unprivileged |
Inside the job:
./linkspan --port 8080 &
curl -X POST http://127.0.0.1:8080/api/v1/jupyter/sessions \
-H 'Content-Type: application/json' -d '{"root_dir": "/home/me/project"}'
curl -X POST http://127.0.0.1:8080/api/v1/vscode/sessions \
-H 'Content-Type: application/json' \
-d "{\"authorized_key\": \"$(cat ~/.ssh/id_ed25519.pub)\"}"Each reply names a loopback port: the Jupyter server's addr, with its token, and the SSH server's bind_port.
The first Jupyter server builds the Python environment, which takes a few minutes. /api/v1/forward/<port> carries
a WebSocket to either through the one control port, so whoever reaches that port reaches every server.
To reach the job from off the node, add --tunnel-enable --tunnel-mode=link --tunnel-link-args="--url <url>" with
LINKSPAN_LINK_TOKEN=<token>, both issued by cs-plane. Without cs-plane, host a Dev Tunnel instead: create it with
devtunnel create, declare only the control port with devtunnel port create <id> -p 8080, mint a token with
devtunnel token <id> --scopes host, and add
--tunnel-enable --tunnel-mode=devtunnel --tunnel-devtunnel-args="--id <id> --cluster <region>" with
LINKSPAN_TUNNEL_HOST_TOKEN=<token>. --tunnel-mode=link,devtunnel runs both. Clients reach every server
through /api/v1/forward on that port.
Every server stops when Linkspan stops, so a job running Linkspan as its main process ends its servers at the walltime.
cs-plane exports LINKSPAN_LINK_TOKEN, CS_LINK_URL and CS_CONTROL_PORT and submits a job like this:
#!/bin/bash
exec linkspan --port "$CS_CONTROL_PORT" --workflow workflow.yaml \
--tunnel-enable --tunnel-mode=link --tunnel-link-args="--url $CS_LINK_URL"With the devtunnel transport, Linkspan fetches the devtunnel CLI on first use and reruns its host process, with
backoff, whenever it exits.
Add #SBATCH --signal=B:USR1@120 to get SIGUSR1 two minutes before the walltime.
A workflow's tasks key lists triggers, each a moment (on, default start) and its steps. A step is an action
with params; shell.exec runs a command, and every other action is a subsystem's, named <subsystem>.<verb>,
whose params are the matching route's request body. Steps run in order; the first failure exits Linkspan with
status 1. Each trigger's run then waits on the servers and processes its steps started. Once start and ready
complete, Linkspan exits, running the stop steps first, so a job ends with its payload or its servers.
| Moment | Runs when |
|---|---|
start |
The listeners are up |
ready |
The start run is complete |
stop |
Linkspan is told to exit, before teardown, with the API still up |
SIGUSR1, SIGUSR2, SIGHUP |
The signal arrives |
| Action | Does | params |
|---|---|---|
shell.exec |
Runs command under sh -c as a process; answers when it ends |
command |
vscode.sessions.select, jupyter.sessions.select, terminal.sessions.select |
Lists servers | |
vscode.sessions.start |
Starts an SSH server | authorized_key |
jupyter.setup |
Builds the Jupyter environment ahead of the first server | |
jupyter.sessions.start, .stop |
Starts or stops a Jupyter server | root_dir, addr, token; id |
terminal.sessions.start, .stop |
Starts or stops a web terminal | cwd; id |
filesystem.mount, .unmount, .copy, .sync |
Not implemented | source, target; unmount only target |
checkpoint.pause |
Checkpoints a running process with CRIU, ending it and the run of the step waiting on it | id |
checkpoint.resume |
Resumes a checkpoint as a process under the same id; answers when it ends | id |
name: train
tasks:
- on: start
steps:
- name: Build the Jupyter environment
action: jupyter.setup
- on: ready
steps:
- name: Jupyter
action: jupyter.sessions.start
params:
root_dir: /home/me/project
- name: Training loop
ref: trainloop
action: shell.exec
params:
command: python /home/me/train.py
- on: SIGUSR1
steps:
- name: Checkpoint before the walltime
action: checkpoint.pause
params:
id: trainloopA step's ref, or a request's "ref", is the id of the server or process it creates; without one Linkspan assigns
it. A repeated ref replaces the earlier one, except a serving SSH server (see VS Code below). An unknown moment,
field or action is refused before anything starts.
| Example | Shows |
|---|---|
examples/workflow.yml |
Each trigger against a local Linkspan |
examples/checkpoint.yml |
A payload paused on SIGUSR1 |
examples/restore.yml |
The next job, resuming it |
examples/checkpoint.sh |
Runs the pair and checks the count is whole |
| Flag | Default | Description |
|---|---|---|
--port |
8080 |
Control port on loopback; 0 picks a free one |
--socket |
HTTP API unix socket path, mode 0600; alone, it replaces the port |
|
--workflow |
Workflow YAML file | |
--tunnel-enable |
false |
Carry the API off the node over the transports of --tunnel-mode |
--tunnel-mode |
Comma-separated transports, link and/or devtunnel; required with --tunnel-enable |
|
--tunnel-link-args |
"--url <ws or wss URL>" of cs-plane; required with the link transport, refused without it |
|
--tunnel-devtunnel-args |
"--id <Dev Tunnel id> --cluster <Dev Tunnels region>" of the Dev Tunnel; required with the devtunnel transport, refused without it |
|
--version |
Print the version and exit |
The API listens on --port, --socket, or both, with the same routes on each; with neither it takes port 8080.
Linkspan replaces a stale socket, refuses any other file at the path, and removes the socket on exit. A socket
connects only on its node, so a caller elsewhere in the cluster reaches it through a Slurm step:
srun --jobid=<id> --overlap curl --unix-socket <path> http://localhost/api/v1/usage. The devtunnel transport
carries the port, so it refuses --socket without --port.
| Environment | Read by |
|---|---|
LINKSPAN_LINK_TOKEN |
The link transport, as the link token |
LINKSPAN_TUNNEL_HOST_TOKEN |
The devtunnel transport, as the host token |
JUPYTER_TOKEN |
jupyter.sessions.start, as the default token |
| Subsystem | Offers |
|---|---|
workflow |
POST /workflow/shell/exec; the shell.exec action stays available regardless |
vscode |
SSH servers for Remote-SSH |
jupyter |
Jupyter servers in a uv-built environment |
terminal |
ttyd web terminals, Linux only |
filesystem |
Mount, unmount, copy and sync, declared and answering 501 |
checkpoint |
Pause and resume of processes with CRIU |
Requests carry no credential; reaching the port or socket is the authorization (SECURITY.md). Every route
answers errors as {"error": "<message>"}: 400 for an unparsable body, 413 over 64KB.
| Method | Path | Answers |
|---|---|---|
| GET | /api/v1/health |
{"status":"ok"} |
| GET | /api/v1/forward/{port} |
WebSocket carrying one TCP connection, in binary frames, to the loopback port a running task serves; 404 otherwise |
| GET | /api/v1/usage |
The job's latest memory, CPU, process, GPU and network sample, taken every 5s; an unreadable value is null |
| POST | /api/v1/workflow/shell/exec |
Takes {"command","ref"}, 400 without command; 200 with the process once it exits 0, 202 once a pause ended it, 500 otherwise |
| GET | /api/v1/vscode/sessions |
[{"id":"s-<port>","addr":"127.0.0.1:<port>","state":"<state>","error":""}] |
| POST | /api/v1/vscode/sessions |
Takes {"authorized_key","ref"}; 201 with {"id":"s-<port>","bind_port":<port>}, or 200 with the same shape when ref is already serving |
| GET | /api/v1/jupyter/sessions |
[{"id":"j-<port>","addr":"127.0.0.1:<port>","state":"<state>","error":"","root_dir":"<dir>","token":"<token>"}] |
| POST | /api/v1/jupyter/sessions |
Takes {"root_dir","addr","token","ref"}; 201 with one server object |
| DELETE | /api/v1/jupyter/sessions/{id} |
{"id":"<id>","state":"stopped"}; 404 for an unknown id |
| POST | /api/v1/jupyter/setup |
200 once the environment is built |
| GET | /api/v1/terminal/sessions |
[{"id":"t-<port>","addr":"127.0.0.1:<port>","state":"<state>","error":"","cwd":"<dir>"}] |
| POST | /api/v1/terminal/sessions |
Takes {"cwd","ref"}; 201 with one server object; 501 off Linux |
| DELETE | /api/v1/terminal/sessions/{id} |
{"id":"<id>","state":"stopped"}; 404 for an unknown id |
| POST | /api/v1/filesystem/{mount,unmount,copy,sync} |
Takes {"source","target"}, unmount only target; 400 for a missing param, else 501 |
| POST | /api/v1/checkpoint/pause |
Takes {"id"}; 200 with {"id","dir"} once the checkpoint is written; 404 for no such running process, 500 with CRIU's error, 501 without CRIU |
| POST | /api/v1/checkpoint/resume |
Takes {"id"}; as shell/exec once the resumed process ends; 404 for no checkpoint, 501 without CRIU |
Lists are ordered by id and [] when empty. An empty root_dir or cwd is Linkspan's working directory.
VS Code. One SSH server per key, on loopback, accepting only that key and running commands through sh. A key
with authorized_keys options is refused with 400. The port accepts before the reply. A ref already serving is
answered as is, whatever key the request names.
Jupyter and terminals. A server starts starting, becomes running once its port accepts, and ends exited on
status 0 or failed with error otherwise; a missing folder fails the server, not the request. It binds loopback
and is reached through /api/v1/forward or the link. addr pins a Jupyter server's loopback address; token
defaults to JUPYTER_TOKEN, else a minted one.
Processes. shell.exec runs under sh -c on Linkspan's stdout and stderr, with id ref or p-<n>, and its
object carries pid. A pause runs criu dump into the checkpoint ~/.cybershuttle/checkpoints/<id>, replacing an
earlier checkpoint only on success; the process ends and its waiting step answers 202, ending its trigger's run.
A resume runs criu restore as a new process under the same id, on the new job's stdout and stderr.
Linkspan is one static Go binary built on three ideas.
- Everything that runs is a task. The listener, the link, the Dev Tunnel host process, the usage sampler, the workflow, each SSH server and each child process are entries of one registry, each a function under a context with an id, an address and a state. Starting a task binds its address first, so the port is reserved before the reply. Stopping Linkspan cancels every task and waits for it; a child dies with its process group.
- An action is both a route and a workflow step. Each subsystem exports a table of actions, plain
functions over a params map, and a route table naming them, so
POST /api/v1/jupyter/sessionsand ajupyter.sessions.startstep run one function. - Building blocks are composed where used.
internal/holds primitives; a subsystem composes them into a task at the point it starts one.
CONTRIBUTING.md has the source layout and checks; docs/COMPATIBILITY.md the client contracts; SECURITY.md the security model and how to report a vulnerability.
Apache-2.0; see LICENSE.
