Skip to main content
Run Pi inside a CoreWeave sandbox to work on a repository from your terminal. Pi’s agent process, files, and shell commands run in the sandbox. Model requests go to your chosen provider. This guide covers creating the workspace, connecting to Pi, checking its work, and stopping compute.

Prerequisites

Before you begin, you need the following:
  • Un terminal macOS ou Linux, Python 3.12 ou version ultérieure, et uv.
  • Une clé API W&B pour accéder au sandbox. Les exemples utilisent explicitement l’authentification W&B.
  • Des identifiants d’authentification pour un fournisseur de modèles pris en charge par Pi. Ce guide utilise W&B Serverless Inference, qui nécessite des crédits d’inférence.
  • L’URL d’un dépôt Git public. Les dépôts privés nécessitent une authentification Git distincte dans le sandbox.

Prepare your local environment

Create a local project and install the Sandbox software development kit (SDK):
Dans le même terminal, remplacez [WANDB-API-KEY] par votre clé API W&B :
The SDK uses this local credential to manage the sandbox. The creation script doesn’t copy it into the sandbox. You configure model authentication separately.

Create the sandbox

Save the following script as create_pi_sandbox.py. It creates a CPU sandbox, installs Pi 0.87.1, and clones the repository. The Node.js image supplies the runtime and Git. If setup fails, the script stops the sandbox before raising the error.
create_pi_sandbox.py
Replace [REPOSITORY-URL] with your repository URL, then run:
Keep the printed sandbox ID. Successful setup prints Pi’s version, 0.87.1. The sandbox remains running after the script exits, until you stop it or its 4-hour lifetime expires. The lifetime includes startup time.

Attach your terminal

Save the following as attach_sandbox.py. It forwards your terminal input to a Bash shell in the sandbox and restores your local terminal settings when the shell exits.
attach_sandbox.py
Replace [SANDBOX-ID] with your sandbox ID:
At the sandbox’s Bash prompt, enter the cloned repository:
Inside this shell, run the provider setup and Pi commands in the following sections.

Choose a model provider

Choisissez l’une des options suivantes. L’authentification auprès de la sandbox et celle auprès du modèle sont distinctes, même lorsqu’elles utilisent toutes deux une clé W&B. Pi peut accéder aux identifiants d’authentification transmis à son processus et peut envoyer le contenu du workspace au fournisseur de modèles sélectionné.

Use Serverless Inference

We recommend W&B Serverless Inference for this walkthrough. The example uses zai-org/GLM-5.2. Choose another model from the model catalog if it better fits your task. Dans le shell de la sandbox, saisissez votre clé d’inférence W&B à l’invite masquée. Si le compte dispose de crédits d’inférence, vous pouvez utiliser la même clé W&B que pour l’accès à la sandbox :
In the sandbox shell, configure Pi’s OpenAI-compatible provider. The following commands create the ~/.pi/agent/models.json file. The quoted heredoc preserves the environment-variable reference so the file doesn’t contain the key:
Pi opens its terminal interface with /workspace/project and zai-org/GLM-5.2 in the status area. Submit a task in Run Pi and check its work to verify model access. The configuration limits each response to 8,192 tokens. If you change models, update the model ID and capabilities to match the provider. For more configuration options, see Pi model configuration.

Use another provider

To use Anthropic or OpenAI directly, choose the corresponding API key and start Pi in the same sandbox shell:
Use /model inside Pi to choose a model available to your provider. The Pi provider documentation linked in the prerequisites covers other providers and account sign-in options.

Run Pi and check its work

If Pi displays a project trust prompt, follow it. To check that Pi can create and read a file in the cloned repository, submit this task in Pi:
Pi can read, write, and edit files and run shell commands. Its tools operate with the permissions of the sandbox process. Review the repository and any Pi extensions you load. See Pi security. After Pi finishes, enter /quit to return to the sandbox shell. Pi prints a To resume this session: line with a pi --session command. Keep that command to reopen this conversation. Verify the file independently:
The output should contain Hello from CoreWeave. For an unattended task with the W&B setup, run Pi in print mode from the same shell:
Print mode processes the prompt, prints Pi’s response, and exits. For another provider, replace the provider and model arguments with your selection.

Reconnect to a conversation

To reconnect while the sandbox is running, run the attach_sandbox.py script again. Re-enter any API keys supplied through the previous shell and return to the /workspace/project directory before starting Pi. To reopen your interactive conversation, replace [SESSION-ID] with the ID from the To resume this session: line Pi printed when you exited:
Alternatively, pi --continue resumes the most recent session for the project. If you ran the print-mode example after your interactive conversation, it resumes the print-mode session. Use --session to return to a specific conversation.

Retrieve the result and stop

Enter exit to leave the sandbox shell. In your local terminal, save the following as collect_pi_result.py:
collect_pi_result.py
To save the file locally and stop compute, replace [SANDBOX-ID] with your sandbox ID and run the script:
This script stops the sandbox only after it retrieves the file. If retrieval fails, fix the error and retry. To stop the sandbox separately when you no longer need its files, save the following as stop_pi_sandbox.py:
stop_pi_sandbox.py
Run the script with your sandbox ID:
Quitter Pi ou le shell n’arrête pas la sandbox. Cet exemple n’utilise aucun montage persistant. Récupérez tous les fichiers dont vous avez besoin avant l’arrêt ou l’expiration de la sandbox. Pour disposer d’un workspace restaurable dans une nouvelle sandbox, configurez des snapshots du système de fichiers lors de la création de la sandbox.

Troubleshoot

Use these checks to resolve common issues:
  • If sandbox creation fails, check your sandbox credential and the sandbox authentication requirements linked in the prerequisites.
  • If Pi can’t authenticate, check that the model credential is exported in the shell that starts Pi. With W&B, also check inference credits and the model ID.
  • If Pi can’t reach its provider, check outbound access to the provider endpoint. Installation and cloning also require access to npm and your Git host.
  • If your connection drops, attach again while the sandbox runs. If you need a process to survive terminal disconnections, use a terminal multiplexer such as tmux.

Next steps

For more information, see the following resources:
Dernière modification le 30 septembre 2026