Skip to main content
Exec runs a command inside an existing sandbox and returns stdout, stderr, exit code, and process metadata. Use shell mode for authored command strings and argv mode when exact argument boundaries matter.

What state changes

  • The sandbox process table changes while the command is running.
  • Files, environment-visible side effects, and services created by the command remain in that sandbox until changed or destroyed.
  • Background commands continue after the API call returns.

Usage

from nullspace import Sandbox

with Sandbox.create() as sandbox:
    result = sandbox.commands.run("echo hello > /workspace/out.txt", shell=True)
    print(result.exit_code)
    print(sandbox.files.read("/workspace/out.txt").strip())
The raw API accepts command, optional args, timeout_secs, cwd, envs, shell, and background. Use shell: true for a shell string. Leave shell false and pass args when you need exact argv boundaries. API reference: execCommand (POST /v1/sandboxes/{id}/exec). Guide: Commands and processes. Example: Examples.