Cortex Sandboxes quickstart

Run your first command in an isolated Linux container in your Snowflake account. After you install, run the command with either the CLI or the Python SDK.

Before you start

You need Python 3.11 or later, pip, and a Snowflake account with Cortex Sandboxes enabled. To get access, contact your Snowflake account representative.

Install

python -m pip install 'snowflake-sandbox-python[cli]'
snow plugin enable snow-sandbox

This installs the SDK and the snow sandbox CLI plugin together. If you already have Snowflake CLI, install into the Python environment it runs from, so it can find the plugin. If snow sandbox is an unknown command after this step, see CLI-specific issues.

Set up a connection

To see the Snowflake connections you have, run:

snow connection list

If the list is empty, create one and test it. Follow the prompts, then use the name you chose in place of your_connection on this page:

snow connection add
snow connection test -c your_connection

Make it your default connection. The CLI guide and the tutorials use the default connection when you don’t name one:

snow connection set-default your_connection

Run a command with the CLI

Use this path to try a sandbox from your terminal without writing any code.

snow sandbox run -c your_connection --command 'python -c "print(40 + 2)"'
# Expected output: 42

The CLI creates the sandbox, runs the command, and removes the sandbox when the command finishes.

To run a Python file instead, pass its path:

snow sandbox run -c your_connection my_script.py

Run a command with the Python SDK

Use this path when you want to create sandboxes from your own code.

Save this as hello.py:

from snowflake.sandbox import Sandbox

with Sandbox.create(connection="your_connection") as sb:
    result = sb.exec(["python", "-c", "print(40 + 2)"])
    print(result.stdout)

Important

Run hello.py from a local terminal, not from a Snowflake Workspace. A sandbox created from a Workspace doesn’t get the credentials it needs to connect back to Snowflake.

Run it:

python hello.py
# Expected output: 42

The with block creates the sandbox and removes it when the block ends, including when the command raises an error. You don’t need a separate cleanup step.

Next steps