Skip to main content

Shell execution

This page is the single map of how to run work inside a running sandbox: one-shot shell commands, live streams, detached processes, optional PTY session HTTP actions, and the code interpreter shortcut. For language-specific runtime details and longer tutorials, still use Code execution, Background commands, and PTY.
Replace <sandbox-id> with your sandbox id. Set VR_API_KEY. Hosted default API base is the same as OpenAPI servers (for example https://api.void-run.com/api). Self-hosted: set VR_API_URL / baseUrl. See SDKs & API.

Capabilities at a glance


1. Synchronous shell execution

Runs the command to completion (subject to timeout, default 30s, max 300s on sync exec). Response data contains stdout, stderr, exitCode. Optional JSON fields on the request: cwd, env, timeout, args (array of extra argv pieces; most callers use a single command string—confirm shape in OpenAPI if you use args).

2. Streaming shell execution (SSE)

Server-Sent Events: event: stdout, stderr, exit (JSON with exitCode). Use for logs and long-running commands instead of polling sync exec.

3. Background commands API

Start a process, then list, wait, kill, or attach (SSE) by PID. REST base path: /sandboxes/{id}/commands/.

4. Code interpreter (runCode / run_code)

Runs a snippet in a supported language; returns CodeExecutionResult at the top level (not the same shape as exec). Streaming callbacks are optional on some SDK versions.
More patterns: Code execution, AI code interpreter example.

5. PTY (interactive terminal)

High-level flow: WebSocket to the ephemeral or session URL, plus REST to create/list/delete sessions. The voidrun CLI does not mirror every PTY WebSocket option; use the SDK or implement the WebSocket from OpenAPI.
Concepts and persistent sessions: PTY, Interactive PTY example.

6. Session-exec (HTTP PTY actions)

POST /sandboxes/{id}/session-exec sends structured actions (create, exec, input, resize, close) to the agent. This complements the WebSocket PTY: useful for thin clients or debugging. There is also POST .../session-exec-stream for streaming variants—see API Reference.
Most applications should use sandbox.pty (WebSocket). Use session-exec when you need request/response HTTP actions against an existing PTY session model.

Choosing a path

  • One-shot automation / CI → sync exec (or runCode for snippets).
  • Live logs → exec-stream or commands.connect.
  • Daemons and workers → commands.run (+ wait/kill).
  • Full-screen CLI / REPL → PTY WebSocket via sandbox.pty.
  • Low-level PTY over HTTP → session-exec / OpenAPI.

Next steps

Code execution

Interpreter depth, timeouts, and best practices

Background commands

REST summary and links

PTY

When to use PTY vs exec

TypeScript SDK

All sandbox methods in one place