Skip to main content
Live. This area is documented as current, user-reliable behavior.

Goal

Run code in a clean, isolated machine from your terminal or a pipeline without creating or cleaning up a sandbox.

Prerequisites

  • A signed-in profile or an API key
  • A sandbox template reference with its digest, from Sandbox templates in the dashboard

Workflow

1
Pass the template with --template.
2
Put the command after --, or pass a script with --script.
3
Copy in local files with --file REMOTE=LOCAL and set variables with --env KEY=VALUE.
4
Read the output in your terminal and check the exit code.

Usage

Flags

  • --template (required): the template reference with its digest.
  • --sandbox-profile: the size of the sandbox, such as ci, customer_code or plugin. Defaults to ci.
  • --file REMOTE=LOCAL: copy a local file to a path in /workspace. Repeat it for more files, up to 100 files and 8 MB in total.
  • --env KEY=VALUE: set an environment variable for the command. Repeat it for more.
  • --script FILE: run a script file instead of a command. Use - to read the script from standard input.
  • --interpreter PROGRAM: the program that runs --script, such as python3 or node. Defaults to sh.
  • --shell: run the words after -- as one shell line, so pipes, && and variables work. Without it the command runs directly, without a shell.
  • --cwd: the working directory. Defaults to /workspace.
  • --command-timeout: seconds the command may run, from 1 to 600. Defaults to 60.

Examples

Output and exit code

The command’s standard output goes to your standard output and its standard error to your standard error, so you can pipe and redirect them as usual. When the command exits with a non-zero code, the CLI exits with the same code. With --output json, the CLI prints the whole result instead: state, exit_code, stdout, stderr, the truncation flags, start_ms and duration_ms. The sandbox is deleted whether the command succeeds, fails or runs out of time.

Expected result

The command’s standard output and standard error are printed to yours, the CLI exits with the command’s exit code, and the sandbox is deleted.

Common failures

  • --template is required. Every run needs a template.
  • give a command after -- or --script, not both. Use one way to say what to run.
  • --file takes REMOTE=LOCAL or --env takes KEY=VALUE. Check the = in each flag.
  • output was cut short. Each stream returns at most 64 KB. Write large output to a file inside the command and print a summary.
  • sandbox run timed_out. The command ran past --command-timeout. Raise it, up to 600 seconds.

Run code in one call

Send code and a command, get back the exit code and output. StackShift starts a fresh sandbox, runs it and deletes the sandbox, all in one request.

Logs, remote execution, and environment variables

Inspect runtime output, execute structured commands, and mutate environment variables safely.