---
title: "Run OpenCode in a sandbox"
description: "Run the OpenCode coding agent in a sandbox and use it from your browser."
---

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

# Run OpenCode in a sandbox

This program creates a sandbox, installs the [OpenCode](https://opencode.ai) coding agent in it and starts its web UI on a public port. You use OpenCode from your browser, and everything it runs stays in the sandbox.

## Before you start

- An API key and a project, set as `SUTRA_API_KEY` and `SUTRA_PROJECT`. See [Projects and API keys](https://docs.jgcp.mistrivedev.com/projects-and-api-keys/).
- Node.js 22 or later.
- The SDK: `npm install @mistrive/anchor`.

## The program

Save it as `opencode.ts` and run it with `npx tsx opencode.ts`.

## What to expect

The program prints a URL when OpenCode is ready. Open it in your browser to use OpenCode. The agent knows it runs in a sandbox: when it starts a server, it gives you the address to reach it.

:::note[Today]
The Today program opens its port with all ports on, so a server that OpenCode starts on another port is reachable at the same host with that port's number in front. See [Ports](https://docs.jgcp.mistrivedev.com/sandboxes/ports/).
:::

## Stop it

Press Ctrl+C. The program deletes the sandbox and everything in it.

:::caution
The port is public: anyone with the URL can use OpenCode in your sandbox until you stop the program. In the Today program every port of the sandbox is public, so the servers OpenCode starts are too. Do not share the URL.
:::

Source: https://docs.jgcp.mistrivedev.com/examples/opencode/index.mdx
