Skip to main content
Run shell commands inside sandboxes with full stdout/stderr capture, real-time streaming, and configurable timeouts.
Sandbox-specific operations use the sandbox proxy URL: https://<sandbox-id-or-name>.sandbox.tensorlake.aiFor named sandboxes, you can use the sandbox name in place of the ID — both in the proxy hostname and in CLI/API commands. For example, https://my-env.sandbox.tensorlake.ai/api/v1/processes and tl sbx exec my-env python main.py work the same as their ID-based equivalents. The proxy resolves the name to the underlying sandbox automatically.Name-based proxy requests require an Authorization header. Unauthenticated access (sandboxes with allow_unauthenticated_access) must use the sandbox ID.

Basic Execution

# Run in an existing sandbox — use the sandbox ID or name
tl sbx exec my-env python -c 'print("Hello from sandbox!")'

# Or create, run, and tear down in one step
tl sbx run python -c 'print("Hello from sandbox!")'

CLI Options

# Timeout is in seconds
tl sbx exec <sandbox-id> --timeout 10 python -c 'print("hi")'

# Run from a specific working directory
tl sbx exec <sandbox-id> --workdir /workspace python main.py

# Inject environment variables into a single command
tl sbx exec <sandbox-id> --env MODE=prod --env DEBUG=0 /bin/sh -lc 'printf "%s %s\n" "$MODE" "$DEBUG"'

# Keep the sandbox after a one-shot run so you can inspect it afterwards
tl sbx run --keep /bin/sh -lc 'echo KEEP_TEST && sleep 1'
A verified --env run printed prod 0. A verified --keep run ended with Sandbox <id> kept alive., and tl sbx ls --all then showed that sandbox as running.

Shell Commands

# Count Python files in /workspace with a pipe
tl sbx exec <sandbox-id> bash -c "ls -la /workspace | grep '.py' | wc -l"

# Redirect stdout and stderr to files
tl sbx exec <sandbox-id> bash -c "python script.py > output.txt 2> errors.txt"

# Chain setup and execution in one shell command
tl sbx exec <sandbox-id> bash -c "cd /workspace && pip install -r requirements.txt && python main.py"

Get Process Output

with client.create_and_connect() as sandbox:
    result = sandbox.run("python", ["-c", "print('hello')"])
    print(result.stdout)
    print(result.stderr)

Interactive Shell

# Open an interactive shell in the sandbox
tl sbx ssh <sandbox-id>

# Use a custom shell
tl sbx ssh <sandbox-id> --shell /bin/sh
tl sbx ssh requires an interactive terminal and automatically resumes a suspended sandbox before opening the PTY session.

Error Handling

# The CLI prints stderr and returns a non-zero exit code on failure
tl sbx exec <sandbox-id> python -c "import nonexistent_module"

Streaming Output

Stream stdout/stderr in real time for long-running commands using Server-Sent Events:
tl sbx exec streams combined output to your terminal while the process runs.

Learn More

Processes

Manage background processes.

File Operations

Read, write, and copy files.

Lifecycle

Sandbox states, resources, and timeouts.