Log inGet started

shell

Updated November 17, 2026

Unix shell commands and byte streams over the engine filesystem.

require("@builtin::modules.api.engine.shell") -- shell (also available as global 'shell')

The shell namespace: 14 functions.

globals/shell/close

shell.close(handle: string)

Release a caller-owned stream handle and terminate any command using it.

Parameters

  • handle string — Stream handle returned by shell.start.

globals/shell/interrupt

shell.interrupt(handle: string, signal: number?) -> boolean

Interrupt a command with signal 2 (SIGINT, the default), or terminate its shell with signal 15 (SIGTERM). Interactive SIGINT returns to the prompt; a command reports 128 plus the signal. Drain output afterwards.

Parameters

  • handle string — Stream handle returned by shell.start.
  • signal number (optional) — 2 or 15.

Returns boolean — Whether the execution was active.

globals/shell/read

shell.read(handle: string) -> ShellStreamRead

Drain up to 64 KiB from each output stream and renew the handle's lease. Output bytes are base64 strings. exitCode is nil while the command runs or output remains buffered; its terminal value accompanies the final bytes.

Parameters

  • handle string — Stream handle returned by shell.start.

Returns ShellStreamRead — Separate output bytes and the terminal exit status when available.

globals/shell/run

shell.run(command: string, sessionKey: string?) -> ShellResult

Execute a command in the engine's emulated Unix shell and return once it has completed. This is the same shell as the MCP bash tool — 60+ builtins (ls, cat, grep, find, echo, ...) operating on the virtual scene filesystem. A command that runs Luau (run, luau, zm, zero) needs the engine's frame loop, and a command whose work is a wait (sleep) cannot take its interval while holding it, so from a coroutine the whole line is queued to run off the frame loop and this yields until it finishes; everything else runs inline. The queued run starts the line again from the top, so a line that had already written a file, sent a request, read input or started a background job comes back with the explanation in stderr and shell.runAsync as the way to run it whole. A command reaches the files the code running it reaches, the jobs it starts and the Luau it runs included: run for code a world ships, it is refused the home folder (/zero/home) the way vfs refuses that code.

Parameters

  • command string — Shell command to execute.
  • sessionKey string (optional) — Which caller's shell session the command runs in. A session holds what a command leaves behind: the directory cd moved to, exports, shell functions, set -e. It hands that to the next command run under the same key. Omit it and the command runs in the session of the caller this code runs on behalf of, the one that caller's bash commands also use; code with no attested caller behind it runs in the session every caller that names none shares. A command run for code a world ships keeps what it leaves behind in a session of that code's own under the key: it reaches that code's next command and never a command of the caller's own.

Returns ShellResult — Command result { stdout, stderr, exitCode, ok }.

local r = shell.run("ls /zero/source")

globals/shell/runAsync

shell.runAsync(command: string, sessionKey: string?) -> string

Asynchronous version of shell.run. Returns a promise ID that resolves to a JSON-encoded result string. Use with task.await().

Parameters

  • command string — Shell command to execute.
  • sessionKey string (optional) — Which caller's shell session the command runs in. A session holds what a command leaves behind: the directory cd moved to, exports, shell functions, set -e. It hands that to the next command run under the same key. Omit it and the command runs in the session of the caller this code runs on behalf of, the one that caller's bash commands also use; code with no attested caller behind it runs in the session every caller that names none shares. A command run for code a world ships keeps what it leaves behind in a session of that code's own under the key: it reaches that code's next command and never a command of the caller's own.

Returns string — Promise ID — pass to task.await() to get the JSON result.

local json = task.await(shell.runAsync("find /zero -name '*.luau'"))

globals/shell/start

shell.start(command: string, interactive: boolean?) -> string

Start a caller-owned command with bounded stdin, stdout and stderr streams. Read the handle at least once every 120 seconds to keep it alive. Close it when finished. An interactive session starts with an empty command and reads complete commands from stdin until exit or EOF.

Parameters

  • command string — Command text, or an empty string for an interactive session.
  • interactive boolean (optional) — Read commands interactively from stdin.

Returns string — Stream handle belonging to this caller and client.

globals/shell/write

shell.write(handle: string, bytes: string, eof: boolean?) -> boolean

Queue input bytes and optionally close stdin. Each chunk is at most 256 KiB. False means the input queue is full or closed: drain output, check its exit status, and retry the same bytes while execution continues.

Parameters

  • handle string — Stream handle returned by shell.start.
  • bytes string — Input bytes.
  • eof boolean (optional) — Close stdin after these bytes.

Returns boolean — Whether the entire chunk was accepted.

typed/builtin//modules/api/engine/shell/shell/close

shell.close(handle: string)

Release a caller-owned stream handle and terminate any command using it.

Parameters

  • handle string — Stream handle returned by shell.start.

typed/builtin//modules/api/engine/shell/shell/interrupt

shell.interrupt(handle: string, signal: number?) -> boolean

Interrupt a command with signal 2 (SIGINT, the default), or terminate its shell with signal 15 (SIGTERM). Interactive SIGINT returns to the prompt; a command reports 128 plus the signal. Drain output afterwards.

Parameters

  • handle string — Stream handle returned by shell.start.
  • signal number (optional) — 2 or 15.

Returns boolean — Whether the execution was active.

typed/builtin//modules/api/engine/shell/shell/read

shell.read(handle: string) -> ShellStreamRead

Drain up to 64 KiB from each output stream and renew the handle's lease. Output bytes are base64 strings. exitCode is nil while the command runs or output remains buffered; its terminal value accompanies the final bytes.

Parameters

  • handle string — Stream handle returned by shell.start.

Returns ShellStreamRead — Separate output bytes and the terminal exit status when available.

typed/builtin//modules/api/engine/shell/shell/run

shell.run(command: string, sessionKey: string?) -> ShellResult

Execute a command in the engine's emulated Unix shell and return once it has completed. This is the same shell as the MCP bash tool — 60+ builtins (ls, cat, grep, find, echo, ...) operating on the virtual scene filesystem. A command that runs Luau (run, luau, zm, zero) needs the engine's frame loop, and a command whose work is a wait (sleep) cannot take its interval while holding it, so from a coroutine the whole line is queued to run off the frame loop and this yields until it finishes; everything else runs inline. The queued run starts the line again from the top, so a line that had already written a file, sent a request, read input or started a background job comes back with the explanation in stderr and shell.runAsync as the way to run it whole. A command reaches the files the code running it reaches, the jobs it starts and the Luau it runs included: run for code a world ships, it is refused the home folder (/zero/home) the way vfs refuses that code.

Parameters

  • command string — Shell command to execute.
  • sessionKey string (optional) — Which caller's shell session the command runs in. A session holds what a command leaves behind: the directory cd moved to, exports, shell functions, set -e. It hands that to the next command run under the same key. Omit it and the command runs in the session of the caller this code runs on behalf of, the one that caller's bash commands also use; code with no attested caller behind it runs in the session every caller that names none shares. A command run for code a world ships keeps what it leaves behind in a session of that code's own under the key: it reaches that code's next command and never a command of the caller's own.

Returns ShellResult — Command result { stdout, stderr, exitCode, ok }.

local r = shell.run("ls /zero/source")

typed/builtin//modules/api/engine/shell/shell/runAsync

shell.runAsync(command: string, sessionKey: string?) -> string

Asynchronous version of shell.run. Returns a promise ID that resolves to a JSON-encoded result string. Use with task.await().

Parameters

  • command string — Shell command to execute.
  • sessionKey string (optional) — Which caller's shell session the command runs in. A session holds what a command leaves behind: the directory cd moved to, exports, shell functions, set -e. It hands that to the next command run under the same key. Omit it and the command runs in the session of the caller this code runs on behalf of, the one that caller's bash commands also use; code with no attested caller behind it runs in the session every caller that names none shares. A command run for code a world ships keeps what it leaves behind in a session of that code's own under the key: it reaches that code's next command and never a command of the caller's own.

Returns string — Promise ID — pass to task.await() to get the JSON result.

local json = task.await(shell.runAsync("find /zero -name '*.luau'"))

typed/builtin//modules/api/engine/shell/shell/start

shell.start(command: string, interactive: boolean?) -> string

Start a caller-owned command with bounded stdin, stdout and stderr streams. Read the handle at least once every 120 seconds to keep it alive. Close it when finished. An interactive session starts with an empty command and reads complete commands from stdin until exit or EOF.

Parameters

  • command string — Command text, or an empty string for an interactive session.
  • interactive boolean (optional) — Read commands interactively from stdin.

Returns string — Stream handle belonging to this caller and client.

typed/builtin//modules/api/engine/shell/shell/write

shell.write(handle: string, bytes: string, eof: boolean?) -> boolean

Queue input bytes and optionally close stdin. Each chunk is at most 256 KiB. False means the input queue is full or closed: drain output, check its exit status, and retry the same bytes while execution continues.

Parameters

  • handle string — Stream handle returned by shell.start.
  • bytes string — Input bytes.
  • eof boolean (optional) — Close stdin after these bytes.

Returns boolean — Whether the entire chunk was accepted.

  • api
  • reference