Skip to content
Processes and Terminals

Processes and Terminals ​

The Processes and Terminals API is provided by envd's process.Process Connect RPC service. It is used to start commands inside the sandbox, connect to existing processes, send input, resize PTYs, and terminate processes.

Before calling this API, see the Sandbox Runtime API to get the envd endpoint and envdAccessToken.

To specify the execution user inside the sandbox, set Authorization: Basic <base64("user:")>. If no user is specified, envd uses the sandbox default user. Request and response bodies use protobuf JSON field names, which are lowerCamelCase.

Connect RPC Paths ​

MethodRequest PathTypeDescription
List/process.Process/ListUnaryList running processes
Start/process.Process/StartServer streamingStart a process and stream process events
Connect/process.Process/ConnectServer streamingConnect to an existing process and stream process events
Update/process.Process/UpdateUnaryUpdate process configuration. Currently mainly used to resize a PTY
SendInput/process.Process/SendInputUnarySend stdin or PTY input to a process
StreamInput/process.Process/StreamInputClient streamingSend input through a client stream and preserve input order
SendSignal/process.Process/SendSignalUnarySend a signal to a process
CloseStdin/process.Process/CloseStdinUnaryClose stdin for a non-PTY process

Data Structures ​

ProcessConfig ​

FieldTypeDescription
cmdstringExecutable command
argsstring[]Command arguments
envsobjectEnvironment variables
cwdstringWorking directory

PTY ​

FieldTypeDescription
size.colsintegerTerminal columns
size.rowsintegerTerminal rows

ProcessSelector ​

Select a process by PID or tag:

FieldTypeDescription
pidintegerProcess ID
tagstringProcess tag

ProcessEvent ​

Start and Connect return a stream of process events:

EventFieldDescription
startpidProcess started and PID assigned
datastdout / stderr / ptyProcess output. Binary fields are represented as base64 in the JSON protocol
endexitCode / exited / status / errorProcess end event
keepaliveNoneKeepalive event

List Processes ​

Request Path ​

http
POST /process.Process/List

Request Parameters ​

The request body is an empty object:

json
{}

Response Fields ​

FieldTypeDescription
processes[].configobjectProcess start configuration
processes[].pidintegerProcess ID
processes[].tagstringProcess tag

Request Example ​

bash
curl -X POST "$ENVD_API_BASE/process.Process/List" \
  -H "X-Access-Token: $ENVD_ACCESS_TOKEN" \
  -H "Authorization: Basic dXNlcjo=" \
  -H "Connect-Protocol-Version: 1" \
  -H "Content-Type: application/json" \
  -d '{}'

Start a Process ​

Request Path ​

http
POST /process.Process/Start

Request Parameters ​

ParameterTypeRequiredDescription
processobjectYesProcess configuration
ptyobjectNoPTY configuration. When provided, the process runs in pseudo-terminal mode
tagstringNoProcess tag
stdinbooleanNoWhether to open stdin. Compatibility field; default behavior is determined by the server

Request Examples ​

Start a regular command:

bash
curl -N -X POST "$ENVD_API_BASE/process.Process/Start" \
  -H "X-Access-Token: $ENVD_ACCESS_TOKEN" \
  -H "Authorization: Basic dXNlcjo=" \
  -H "Connect-Protocol-Version: 1" \
  -H "Content-Type: application/json" \
  -d '{
    "process": {
      "cmd": "bash",
      "args": ["-lc", "echo hello"]
    },
    "tag": "hello"
  }'

Start a PTY:

json
{
  "process": {
    "cmd": "bash",
    "args": ["-i", "-l"],
    "envs": {
      "TERM": "xterm"
    },
    "cwd": "/home/user"
  },
  "pty": {
    "size": {
      "cols": 80,
      "rows": 24
    }
  },
  "tag": "terminal"
}

Connect to an Existing Process ​

Request Path ​

http
POST /process.Process/Connect

Request Parameters ​

ParameterTypeRequiredDescription
process.pidintegerOne of twoConnect by PID
process.tagstringOne of twoConnect by tag

Request Example ​

json
{
  "process": {
    "pid": 1234
  }
}

Send Input ​

Request Path ​

http
POST /process.Process/SendInput

Request Parameters ​

ParameterTypeRequiredDescription
processobjectYesProcess selector
input.stdinbytesOne of twostdin input for a non-PTY process
input.ptybytesOne of twoPTY input

In the JSON protocol, bytes fields are represented as base64.

Request Example ​

json
{
  "process": {
    "tag": "terminal"
  },
  "input": {
    "pty": "ZWNobyBoZWxsbwo="
  }
}

Resize a PTY ​

Request Path ​

http
POST /process.Process/Update

Request Parameters ​

ParameterTypeRequiredDescription
processobjectYesProcess selector
pty.size.colsintegerNoNew terminal column count
pty.size.rowsintegerNoNew terminal row count

Request Example ​

json
{
  "process": {
    "tag": "terminal"
  },
  "pty": {
    "size": {
      "cols": 120,
      "rows": 40
    }
  }
}

Send a Signal ​

Request Path ​

http
POST /process.Process/SendSignal

Request Parameters ​

ParameterTypeRequiredDescription
processobjectYesProcess selector
signalstring or integerYesSignal. Available values include SIGNAL_SIGTERM (15) and SIGNAL_SIGKILL (9)

Close stdin ​

Request Path ​

http
POST /process.Process/CloseStdin

Request Parameters ​

ParameterTypeRequiredDescription
processobjectYesProcess selector

CloseStdin only applies to non-PTY processes. In PTY scenarios, send Ctrl+D (0x04) to indicate EOF.