> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# stackshift sandbox run

> Run a command or script in a fresh sandbox, print its output and delete the sandbox, in one command.

> [!TIP]
>
> **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

**Step 1**

Pass the template with `--template`.

**Step 2**

Put the command after `--`, or pass a script with `--script`.

**Step 3**

Copy in local files with `--file REMOTE=LOCAL` and set variables with `--env KEY=VALUE`.

**Step 4**

Read the output in your terminal and check the exit code.

## Usage

```bash theme={null}
stackshift sandbox run --template TEMPLATE [flags] -- COMMAND [ARG...]
stackshift sandbox run --template TEMPLATE --script FILE [--interpreter PROGRAM]
```

## 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

```bash theme={null}
stackshift sandbox run --template TEMPLATE@sha256:DIGEST -- uname -a
stackshift sandbox run --template TEMPLATE@sha256:DIGEST --file main.py=./main.py -- python3 main.py
stackshift sandbox run --template TEMPLATE@sha256:DIGEST --file package.json=./package.json --shell -- "npm install && npm test"
echo "print(6 * 7)" | stackshift sandbox run --template TEMPLATE@sha256:DIGEST --script - --interpreter python3
stackshift sandbox run --template TEMPLATE@sha256:DIGEST --env MODE=check --command-timeout 300 -- ./check.sh
```

## 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

> [!TIP]
>
> 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

> [!WARNING]
>
> * `--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.

## Related guides

> [card] [Run code in one call](https://docs.stackshift.cloud/computers/run-code.md)
>
> 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.

> [card] [Logs, remote execution, and environment variables](https://docs.stackshift.cloud/cli/logs-exec-and-environment.md)
>
> Inspect runtime output, execute structured commands, and mutate environment variables safely.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.