Skip to content

Commands and processes

Run commands, stream their output, drive PTYs and terminals, and manage background processes.

Every method shows the same operation in each SDK; pick a language once and every tab on the site follows it.

Python TypeScript Go Ruby Java

An authenticated ProcessService connection. Close it when no longer needed.

def connect(self, pid: int, *, from_start: bool=False) -> Iterator[pb.ProcessEvent]

Events of a running process from now on, reattached from the offsets seen if the connection breaks.

With from_start=True the output the guest still holds (the last 256 KiB of each stream) is replayed first, so a process that wrote before this call (a shell prompt, the echo of a command) is not missed.

Parameter Type Default
pid int
from_start bool False

Returns Iterator[pb.ProcessEvent]

Source: sdk/python/svm/process.py:512
def list(self) -> list[ProcessInfo]

Returns list[ProcessInfo]

Source: sdk/python/svm/process.py:438
def close(self) -> None

Close the channel; a later call on this client opens a new one. A connect in flight ends (its iterator stops) and does not reconnect; a run in flight raises ProcessError.

Raises ProcessError

Source: sdk/python/svm/process.py:272
def close_stdin(self, pid: int) -> None

Send EOF to a process’s stdin.

Parameter Type Default
pid int
Source: sdk/python/svm/process.py:474

Not in the Python SDK’s ProcessClient.

Not in the Python SDK’s ProcessClient.

Not in the Python SDK’s ProcessClient.

def kill(self, pid: int) -> bool

SIGKILL a process; False when it was not found or had already exited.

Parameter Type Default
pid int

Returns bool

Source: sdk/python/svm/process.py:452
def run(self, command: str, *, background: bool=False, on_stdout: Callable[[str], None] | None=None, on_stderr: Callable[[str], None] | None=None, cwd: str | None=None, envs: dict[str, str] | None=None, user: str | None=None, timeout_seconds: int=0, tag: str | None=None, stdin: str | bytes | None=None, sandbox_profile: str | None=None) -> ProcessResult | CommandHandle
def run(self, command: str, *, background: Literal[False]=False, on_stdout: Callable[[str], None] | None=None, on_stderr: Callable[[str], None] | None=None, cwd: str | None=None, envs: dict[str, str] | None=None, user: str | None=None, timeout_seconds: int=0, tag: str | None=None, stdin: str | bytes | None=None, sandbox_profile: str | None=None) -> ProcessResult
def run(self, command: str, *, background: Literal[True], on_stdout: Callable[[str], None] | None=None, on_stderr: Callable[[str], None] | None=None, cwd: str | None=None, envs: dict[str, str] | None=None, user: str | None=None, timeout_seconds: int=0, tag: str | None=None, stdin: str | bytes | None=None, sandbox_profile: str | None=None) -> CommandHandle

Run command through the sandbox’s login shell and return its result, or (background=True) a CommandHandle on the started command: its pid, wait(), disconnect(), kill(), send_stdin, close_stdin and its output events by iteration. With on_stdout / on_stderr a background command’s output is fed to them from a background thread.

sandbox_profile confines the command and its children with Landlock inside the microVM: "read-only", "workspace-only" (read-write in cwd, read-only system paths) or "workspace-offline" (that, and no TCP connect or listen). A kernel that cannot enforce it refuses the command with an error; it never runs unconfined.

stdin feeds the process and, for a foreground command, closes its stdin; for a background one it is what the process reads first and its stdin stays open (stdin="" just opens it) for send_stdin, stream_input and close_stdin. Without stdin the process’s stdin is closed. timeout_seconds kills the process; the result then has timed_out.

Parameter Type Default
command str
background bool False
on_stdout Callable[[str], None] | None None
on_stderr Callable[[str], None] | None None
cwd str | None None
envs dict[str, str] | None None
user str | None None
timeout_seconds int 0
tag str | None None
stdin str | bytes | None None
sandbox_profile str | None None

Returns ProcessResult \| CommandHandle

Source: sdk/python/svm/process.py:344
def send_stdin(self, pid: int, data: str | bytes) -> None
Parameter Type Default
pid int
data str | bytes
Source: sdk/python/svm/process.py:499
def signal(self, pid: int, name: str | int='TERM') -> bool

Send a signal ("TERM", "SIGTERM", "SIGNAL_SIGTERM" or "term"; also INT, HUP, USR1, USR2, STOP, CONT, KILL) to a process; False when it was not found or had already exited. kill is signal(pid, "KILL").

Parameter Type Default
pid int
name str | int 'TERM'

Returns bool

Source: sdk/python/svm/process.py:456
def stream_input(self, pid: int, chunks: 'Iterable[str | bytes]') -> None

Send stdin as one client stream: each chunk is a message, and the stream ends when chunks does.

Parameter Type Default
pid int
chunks 'Iterable[str | bytes]'
Source: sdk/python/svm/process.py:478
Python TypeScript Go Ruby Java

A background command started by run(..., background=True): its pid and the calls that act on it.

wait() follows the command to its end and returns its ProcessResult; iterating the handle yields its output events (both replay what the guest still holds from the start). disconnect() stops following without killing the command; a later wait() or iteration follows it again. kill(), send_stdin(data) and close_stdin() act on the command itself.

Python exposes these as methods; see below.

def close_stdin(self) -> None

Send EOF to the command’s stdin.

Source: sdk/python/svm/process.py:229
def disconnect(self) -> None

Stop following the command (its callbacks, a wait() and any iteration end) without killing it. A later wait() or iteration follows it again.

Source: sdk/python/svm/process.py:212

Not in the Python SDK’s CommandHandle.

Not in the Python SDK’s CommandHandle.

Not in the Python SDK’s CommandHandle.

Not in the Python SDK’s CommandHandle.

def kill(self) -> bool

SIGKILL the command; False when it had already exited.

Returns bool

Source: sdk/python/svm/process.py:221
def send_stdin(self, data: str | bytes) -> None

Write data to the command’s stdin (start it with stdin="" to keep stdin open).

Parameter Type Default
data str | bytes
Source: sdk/python/svm/process.py:225
def wait(self) -> ProcessResult

Follow the command until it ends and return its result: the output (replayed from the start, as far as the guest still holds it), exit code and signal. With callbacks this is what they were fed. A disconnect() while waiting returns what was seen so far, without an exit code.

Returns ProcessResult

Source: sdk/python/svm/process.py:195

Not in the Python SDK’s CommandHandle.

Python TypeScript Go Ruby Java

The outcome of a command, or the start of a background command or PTY. pid is envd’s process handle (small numbers such as 1, 4, 6), the value kill, connect, send_stdin and the PTY calls take; it is not the guest kernel’s pid (run echo $$ in the command for that).

Property Type Description
error str
exit_code int | None
output_dropped bool
pid int
signal str
timed_out bool
stderr: str

Property (read-only).

stdout: str

Property (read-only).

Not in the Python SDK’s ProcessResult.

Python TypeScript Go Ruby Java

ProcessInfo is a running process returned by ProcessService.List.

Property Type Description
args tuple[str, ...]
cmd str
pid int
tag str | None
Python TypeScript Go Ruby Java

Typed envd failure; branch on code rather than the message. A SandboxError like every other error this package raises, so one except SandboxError covers a refused file write, a refused command and an API failure.

A data-plane failure is also the REST error of the same cause: a missing path or process is a NotFoundError (and error_kind says not_found), a refused one a PermissionDeniedError, and so on by its gRPC status.

Python exposes these as methods; see below.

Not in the Python SDK’s ProcessError.

Not in the Python SDK’s ProcessError.

Not in the Python SDK’s ProcessError.

Not in the Python SDK’s ProcessError.

Not in the Python SDK’s ProcessError.

Python TypeScript Go Ruby Java

PTY surface sharing an authenticated ProcessService client.

def connect(self, pid: int, *, from_start: bool=False) -> Iterator[pb.ProcessEvent]

Events of the terminal from now on; from_start=True replays the output the guest still holds first.

Parameter Type Default
pid int
from_start bool False

Returns Iterator[pb.ProcessEvent]

Source: sdk/python/svm/pty_client.py:47
def create(self, command: str | None=None, *, cols: int=80, rows: int=24, args: list[str] | None=None, cwd: str | None=None, envs: dict[str, str] | None=None, user: str | None=None, on_data: Callable[[str], None] | None=None, sandbox_profile: str | None=None) -> 'ProcessResult'

Start command (the guest’s shell by default) in a cols x rows terminal and return once the process has started: the result carries the pid (the envd process handle) and no output or exit code, since a terminal runs until it is ended. Output arrives through on_data (called from a background thread) or connect(pid); send keys with send_input and end it with kill. Without on_data the output written before you connect is replayed by connect(pid, from_start=True).

Parameter Type Default
command str | None None
cols int 80
rows int 24
args list[str] | None None
cwd str | None None
envs dict[str, str] | None None
user str | None None
on_data Callable[[str], None] | None None
sandbox_profile str | None None

Returns 'ProcessResult'

Source: sdk/python/svm/pty_client.py:22
def close(self) -> None
Source: sdk/python/svm/pty_client.py:51

Not in the Python SDK’s PtyClient.

Not in the Python SDK’s PtyClient.

Not in the Python SDK’s PtyClient.

def kill(self, pid: int) -> bool
Parameter Type Default
pid int

Returns bool

Source: sdk/python/svm/pty_client.py:44
def resize(self, pid: int, *, cols: int, rows: int) -> None
Parameter Type Default
pid int
cols int
rows int
Source: sdk/python/svm/pty_client.py:33
def send_input(self, pid: int, data: str | bytes) -> None
Parameter Type Default
pid int
data str | bytes
Source: sdk/python/svm/pty_client.py:36
def stream_input(self, pid: int, source: 'Iterable[str | bytes]') -> None

Send keys to the terminal as one client stream: each chunk of source is a message, and the stream ends when it does. The bytes go to the terminal’s input (ProcessInput.pty), as send_input sends them.

Parameter Type Default
pid int
source 'Iterable[str | bytes]'
Source: sdk/python/svm/pty_client.py:39
Python TypeScript Go Ruby Java

Terminals are long-lived tmux sessions an agent can start, type into, read the screen of and wait on; they keep running when the client disconnects.

def list(self) -> list[str]

Returns list[str]

Source: sdk/python/svm/terminals.py:86

Not in the Python SDK’s Terminals.

def attach_command(self, name: str) -> str

The command to run in sandbox.pty to attach interactively; detaching leaves the terminal running.

Parameter Type Default
name str

Returns str

Source: sdk/python/svm/terminals.py:96

Not in the Python SDK’s Terminals.

def ensure(self, *, timeout_seconds: int=300) -> None

Install tmux if it is missing.

Parameter Type Default
timeout_seconds int 300
Source: sdk/python/svm/terminals.py:40

Not in the Python SDK’s Terminals.

def is_alive(self, name: str) -> bool
Parameter Type Default
name str

Returns bool

Source: sdk/python/svm/terminals.py:90
def kill(self, name: str) -> bool
Parameter Type Default
name str

Returns bool

Source: sdk/python/svm/terminals.py:93
def screen(self, name: str, *, scrollback: int=0) -> str

The visible screen, plus up to scrollback earlier lines.

Parameter Type Default
name str
scrollback int 0

Returns str

Source: sdk/python/svm/terminals.py:70
def send_keys(self, name: str, *keys: str) -> None

Press named keys such as Enter, C-c, Up or Escape.

Parameter Type Default
name str
keys str optional
Source: sdk/python/svm/terminals.py:64
def send_text(self, name: str, text: str, *, enter: bool=True) -> None

Type text literally; enter then presses Enter.

Parameter Type Default
name str
text str
enter bool True
Source: sdk/python/svm/terminals.py:58
def start(self, name: str, command: str | None=None, *, cols: int=200, rows: int=50, cwd: str | None=None) -> str
Parameter Type Default
name str
command str | None None
cols int 200
rows int 50
cwd str | None None

Returns str

Source: sdk/python/svm/terminals.py:47
def wait_for(self, name: str, pattern: str, *, timeout: float=60.0, interval: float=0.5, scrollback: int=200) -> str

Poll the screen until pattern (a regular expression) appears; returns the screen. TimeoutError otherwise.

Parameter Type Default
name str
pattern str
timeout float 60.0
interval float 0.5
scrollback int 200

Returns str

Raises TimeoutError

Source: sdk/python/svm/terminals.py:75
Python TypeScript Go Ruby Java

Sessions are named shells whose state lives in the sandbox (~/.fcap/sessions, owner-only), so it survives pause and resume.

def create(self, name: str, *, cwd: str | None=None, envs: dict[str, str] | None=None) -> str
Parameter Type Default
name str
cwd str | None None
envs dict[str, str] | None None

Returns str

Source: sdk/python/svm/sessions.py:53
def list(self) -> list[str]

Returns list[str]

Source: sdk/python/svm/sessions.py:62
def close(self, name: str) -> None
Parameter Type Default
name str
Source: sdk/python/svm/sessions.py:66

Not in the Python SDK’s Sessions.

Not in the Python SDK’s Sessions.

def run(self, name: str, command: str, *, timeout_seconds: int=0, **options: object) -> ProcessResult
Parameter Type Default
name str
command str
timeout_seconds int 0
options object optional

Returns ProcessResult

Source: sdk/python/svm/sessions.py:59
Python TypeScript Go Ruby Java

The responses of a process stream, continuing across breaks until the process ends.

open_stream(pid, offsets) opens Start while pid is None and Connect after, from offsets (stdout, stderr) or from now when they are None; lookup() finds the pid of a process whose start event was never seen, or None. Every stream’s start event says where it begins, which is where a break resumes.

Property Type Description
cancelled bool
def cancel(self) -> None
Source: sdk/python/svm/resume.py:65