Skip to main content
Run OpenCode against a repository in a CoreWeave sandbox. Send a task from your terminal, check the resulting files, and save the workspace for later. The agent process, workspace, and commands run in the sandbox. Model requests go to your configured provider.

Prerequisites

Before you begin, you need the following:
  • Une clé API W&B pour accéder au sandbox. Ces exemples utilisent l’authentification W&B.
  • Un accès à un modèle via W&B Serverless Inference ou un autre fournisseur OpenCode. L’accès au fournisseur et sa facturation sont distincts de l’accès au sandbox.
  • L’URL d’un dépôt public. Pour les dépôts privés, des identifiants Git sont nécessaires dans le sandbox.
  • cws-agent, installé selon ses instructions d’installation.
Dans votre terminal local, remplacez [WANDB-API-KEY] par votre clé API W&B complète :
Supprimez la variable CWSANDBOX_API_KEY pour que cws-agent sélectionne l’authentification W&B.

Launch OpenCode with cws-agent

Utilisez cws-agent pour installer OpenCode dans un sandbox, cloner votre dépôt dans le répertoire /workspace/project et configurer un montage de snapshot pour les snapshots du système de fichiers. Choose one of the following provider options. Replace [SANDBOX-NAME] with a session name containing 1 to 40 lowercase letters, digits, or hyphens. Start the name with a letter or digit. Replace [REPOSITORY-URL] with your public repository URL. W&B Serverless Inference is the preferred provider for this guide. You can use it to access hosted open models. You can use any model and provider supported by OpenCode instead. Follow Use another model provider. Complete the W&B Serverless Inference prerequisites, including a W&B project, and check your available inference credits. This example selects GLM 5.2 explicitly:
Le préréglage --wandb configure le point de terminaison d’inférence de W&B, transmet WANDB_API_KEY au sandbox et restreint OpenCode à ce fournisseur. L’agent peut utiliser cette clé à la fois pour l’inférence et pour l’accès au sandbox. Pour choisir un autre modèle W&B, remplacez zai-org/GLM-5.2 par un ID figurant dans la liste des modèles disponibles.

Use another model provider

To use another provider, omit --wandb and --wandb-model when you create the sandbox. Export that provider’s API key locally. For example, choose one of these alternatives and replace the key placeholder:
Replace [PROVIDER-ID]/[MODEL-ID] in both fields with your OpenCode model identifier, using the anthropic/ or openai/ provider prefix as appropriate. The small_model field selects the model for lightweight tasks such as title generation. See OpenCode models.
If they’re set, cws-agent forwards ANTHROPIC_API_KEY and OPENAI_API_KEY. For providers whose keys aren’t forwarded automatically, follow their OpenCode provider configuration and use --env-passthrough [VARIABLE-NAME] for additional environment variables. Both launch options print session ready. after setup. --detach leaves the sandbox running without opening the terminal interface or importing local skills and Model Context Protocol (MCP) configuration. The 2-hour lifetime is a wall-clock limit, including setup. Stop compute when you finish.

Run a task and check the result

From your local terminal, ask OpenCode to write and read a file:
This runs OpenCode without an interactive terminal. --permission-mode native keeps OpenCode’s configured permissions. Without it, cws-agent defaults to accepting approval requests. If your OpenCode policy requires approval for the task, use an interactive session to approve it. See OpenCode permissions. Check the actual file independently of the agent’s response:
The output should be Hello from CoreWeave. Before you stop compute, retrieve a local copy:

Optional: Work interactively

From an interactive terminal on macOS or Linux, open OpenCode in the same workspace:
The --no-config-sync flag skips local skills and MCP imports. Send prompts and approve actions in OpenCode, then use /exit to return to your local terminal. When you exit OpenCode, the sandbox continues to run. Repeat the connection command to open OpenCode again. It doesn’t automatically select a previous conversation. For conversation history and resume commands, see cws-agent sessions.

Save, stop, and restore

After the agent finishes, snapshot the workspace and stop compute:
down saves the /workspace directory before stopping the sandbox. If the snapshot fails, the sandbox remains running. Inspect the error and retry after resolving it. To stop without waiting for an explicit snapshot, run:
Don’t rely on this command to save changes. Copy results elsewhere or confirm a completed snapshot before stopping. Restore requires a completed snapshot. To return to a workspace saved with W&B inference, make sure WANDB_API_KEY is still exported in your local terminal, then run:
Use the same --wandb-model value you launched with. If you omit it while using --wandb, restore selects the preset’s default model. For another provider, re-export its key and OPENCODE_CONFIG_CONTENT, then run:
Restore creates a new sandbox from the saved workspace. Supply environment-only credentials again. Snapshots can contain saved OpenCode logins and conversation data, but they don’t preserve running processes. Run the file check again to confirm the sandbox-proof.txt file survived. Continue with cws-agent run or the interactive connection command. Stop the restored sandbox with cws-agent down when you finish.

Troubleshoot

If setup or a task fails, use the following checks:
  • L’authentification au sandbox échoue : vérifiez que la clé API W&B est complète, ainsi que votre accès au sandbox.
  • Les requêtes vers le modèle W&B échouent : vérifiez l’accès à l’inférence, les crédits et l’ID du modèle. L’accès au sandbox ne suffit pas à lui seul pour accéder à l’inférence.
  • Un autre fournisseur n’est pas disponible : démarrez une nouvelle session sans --wandb. Le préréglage W&B est enregistré dans le workspace : omettre --wandb lors de la restauration ne le supprime donc pas. Pour un workspace existant, voir Configuration du préréglage W&B.
  • Une tâche en mode headless nécessite une approbation : connectez-vous de manière interactive et répondez aux invites d’approbation d’OpenCode avant de continuer.

Next steps

For more information, see these guides:
Dernière modification le 30 septembre 2026