process.exec for bounded commands where you need the result before continuing. use process.spawn for agents, servers, watchers, interactive shells, and other long-running processes. after spawning a process, you can inspect its status, stream its output, send input, resize its pty, or terminate it.
if your task only needs to control the page itself, use one of Kernel’s browser control options instead — playwright execution, computer use, CDP, or WebDriver BiDi. use process execution when you need an executable, operating-system tools, a long-running process, or direct filesystem access. for workloads that need their own deployment and invocation lifecycle, use KERNEL apps.
common production patterns
- co-locate an agent with its browser. browser agents often make many small tool calls. upload an agent binary with file i/o, run it alongside chromium, and point it at the local playwright daemon to remove a round trip through KERNEL’s public api from each call. see the fx co-located agent cookbook for an end-to-end example.
- process downloads before retrieving them. unpack archives, extract text from documents, resize images, or compress a directory while the files are still alongside the browser, then retrieve only the final artifacts with file i/o.
- run existing command-line tools. upload a pinned binary or script and call it from the same workflow instead of rewriting it as browser automation code.
- start a session-local helper. run a local server, callback handler, or file watcher for as long as the browser task needs it.
- measure memory headroom. read the session’s memory allocation and per-process usage with
freeandpsto size a workload or catch growth before chromium runs out. see measure memory and cpu usage. - inspect failed browser tasks. run tools such as
curl,ps, andlsto inspect network responses, running processes, logs, and downloaded files before the browser is deleted.
Run a command synchronously
process.exec runs a command and blocks until it exits or times out. stdout_b64 and stderr_b64 are base64-encoded, and exit_code tells you whether it succeeded.
cwd to set a working directory, env to pass environment variables, as_user/as_root to control privileges, and timeout_sec to cap execution time.
Run a command in the background
process.spawn starts a command without waiting for it to finish, returning a process_id you use to manage it afterward. This is the right call for long-running processes — a server, a watcher script, an interactive shell.
allocate_tty: true to attach a pseudo-terminal for interactive shells, with cols/rows to set its initial size.
Manage a running process
Check status
Poll for whether a spawned process is still running, and its resource usage:Stream stdout and stderr
Read output from a spawned process as it happens over server-sent events:Write to stdin
Send base64-encoded input to a running process, e.g. to answer an interactive prompt:Resize a PTY
Resizing only works on a process spawned withallocate_tty: true — calling it on a plain process returns a 400. Match the terminal to a live view or client window:
Kill a process
signal accepts TERM, KILL, INT, or HUP.
Measure memory and CPU usage
Kernel doesn’t expose a per-session memory metric in the API, CLI, or dashboard today, so read it from inside the session instead. Standard Linux tools see the browser’s full memory allocation and every Chromium process.Read whole-session memory
free reports the memory allocated to your browser. A headless browser gets 1 GiB; a headful, non-GPU browser gets 8 GiB by default and 16 GiB when you set memory on create.
available is the number to watch. used excludes page cache, which the kernel reclaims under pressure, so a session with almost no free memory can still be healthy.
Break usage down by process
ps gives you resident set size per process, in KiB, highest first:
chromium rows rather than one large one. Sum them for the browser’s real footprint:
Sample over time
A single reading tells you little about a run that fails after twenty minutes. Spawn a sampler and stream it to compute percentiles or alert on a threshold:process.status reports mem_bytes only for processes you started through process.spawn, so it won’t tell you anything about Chromium, and it doesn’t populate CPU usage. Use ps or top -b -n1 for both.system telemetry category. Its system_oom_kill event carries the killed process’s RSS along with total and free memory, which tells you what the session looked like when it ran out — but only after the fact, so pair it with sampling if you need to catch pressure before a crash.
Root and per-user execution
Passas_root: true or as_user: "<name>" on exec or spawn to control which user the command runs as. This is safe because a Kernel browser is a unikernel VM with no shared host kernel — root inside your session has no path to other customers or platform infrastructure.
Via CLI
The CLI exposes the same operations:Related
File I/O
Upload and download files from a browser VM
SSH Access
Open an interactive SSH session for debugging
CLI reference
All
kernel browsers process subcommands and flags