Skip to main content

Workspace Commands

Each DevPod command on a workspace can be streamed over DevPod.Pro via a websocket. The websocket needs an access key either via the Authorization header or via a cookie called loft_access_key. Then you can call one of the DevPod commands via the following websocket:

wss://<DOMAIN>/kubernetes/management/apis/management.loft.sh/v1/namespaces/loft-p-<PROJECT_ID>/devpodworkspaceinstances/<WORKSPACE_ID>/<ACTION>

Streaming Format

The websocket will stream the stdin, stdout and stderr of the underlying DevPod command executed. You can find the complete protocol implementation here.

To just print stdout and stderr, you can use the following JavaScript snippet:

const StdoutData = 0;
const StderrData = 2;
const ExitCode = 6;

Cookies.set("loft_access_key", "my-access-key")
const ws = new WebSocket(`wss://...`)
ws.binaryType = "arraybuffer"

const textDecoder = new TextDecoder("utf-8")
ws.addEventListener("message", async (event) => {
const arr = new Int8Array(event.data)
const typeByte = arr[0]
const msg = arr.slice(1)

switch (typeByte) {
case StdoutData:
case StderrData: {
const str = textDecoder.decode(msg)
console.info(JSON.parse(str).message)
}
case ExitCode: {
const exitCode = msg[0]
if (exitCode === 0) {
console.info("Command was successful")
} else {
console.info("Command failed with exit code", exitCode)
}
}
}
})

DevPod Up

To start the workspace with WebMode (without expecting DevPod Desktop on the other side), use the following websocket path:

wss://<DOMAIN>/kubernetes/management/apis/management.loft.sh/v1/namespaces/loft-p-<PROJECT_ID>/devpodworkspaceinstances/<WORKSPACE_ID>/up?options=<OPTIONS>&webMode=true&debug=false

Options

JSON encoded DevPod up options

DevPod Stop

To stop the workspace, use the following websocket path:

wss://<DOMAIN>/kubernetes/management/apis/management.loft.sh/v1/namespaces/loft-p-<PROJECT_ID>/devpodworkspaceinstances/<WORKSPACE_ID>/stop

DevPod Status

To retrieve the workspace status, use the following websocket path:

wss://<DOMAIN>/kubernetes/management/apis/management.loft.sh/v1/namespaces/loft-p-<PROJECT_ID>/devpodworkspaceinstances/<WORKSPACE_ID>/get-status?options=<OPTIONS>&debug=false

Options

JSON encoded DevPod status options

DevPod Ssh

To ssh into the workspace, use the following websocket path:

wss://my-devpod-pro-instance.com/kubernetes/management/apis/management.loft.sh/v1/namespaces/loft-p-<PROJECT_ID>/devpodworkspaceinstances/<WORKSPACE_ID>/ssh

DevPod Delete

To delete the workspace, use the following websocket path:

wss://my-devpod-pro-instance.com/kubernetes/management/apis/management.loft.sh/v1/namespaces/loft-p-<PROJECT_ID>/devpodworkspaceinstances/<WORKSPACE_ID>/delete?options=<OPTIONS>&debug=false
warning

This will not delete the workspace object in DevPod.Pro and only will execute the devpod delete command on the DevPod.Pro server.

Options

JSON encoded DevPod delete options