---
title: "MCP server for RL environments"
description: "Connect Claude.ai, Claude Code, ChatGPT, Codex, Cursor, VS Code or the OpenAI Agents SDK to Sandworld by URL, with nothing to install: start episodes, call environment tools and verify results. Sign in with OAuth to use your own workspace."
source: https://sandworld.dev/docs/mcp
---

# MCP server

Sandworld's environments are a Model Context Protocol server. Connect any MCP client to it by URL, with nothing to install, or run the same server locally over stdio. Both offer the same tools, with the API's keys and rate limits.

## Connect by URL

```text
https://sandworld.dev/mcp
```

The server speaks Streamable HTTP and keeps no session: episodes are stored by id, so a client can reconnect at any time and carry on. There are three ways in:

- **Sign in with Sandworld (OAuth).** Claude.ai, ChatGPT, Claude Code, Codex and other clients that support MCP sign-in open a Sandworld window: you sign in, see what the app is asking for and allow it. The app then acts as your workspace, with an API key's limits, episodes private to your workspace and the [workspace tools](https://sandworld.dev/docs/mcp#workspace-tools). See [how sign-in works](https://sandworld.dev/docs/mcp#oauth).
- **No sign-in.** The anonymous sandbox, rate-limited per IP like the [anonymous API](https://sandworld.dev/docs/api#rate-limits). Apps that connect from their own cloud (Claude.ai, ChatGPT) share their addresses' budget with every other user of that app.
- **An [API key](https://sandworld.dev/docs/api#authentication)**, for clients that can send headers: `Authorization: Bearer sw_live_…`, with exactly the key's scopes and limits.

Signing in is lazy: connecting, listing tools and the episode tools work without an account, and the app asks you to sign in when it first needs your workspace (or straight away, if you choose that when adding it). A key or token that isn't valid is refused rather than ignored.

### Claude.ai (custom connector)

1. Go to **Customize → Connectors**, click **+ Add**, then **Add custom connector**.
2. Name it _Sandworld_, enter `https://sandworld.dev/mcp` as the remote MCP server URL, and click **Continue** through the detected settings.
3. Under **Authentication**, choose **Sign in when needed**. Under **OAuth client**, choose **Use Claude's published identity** (Sandworld reads Claude's Client ID Metadata Document, so nothing is registered); **Register automatically** works too. Click **Add**.
4. In a chat, open **+ → Connectors**, switch Sandworld on and ask _“show my Sandworld workspace”_. Claude shows a **Connect** card: a Sandworld window opens, you sign in, check that it sends you back to `claude.ai`, and click **Allow**. From then on Claude acts as your workspace.

Free plans allow one custom connector. On Team and Enterprise, an Owner adds the connector for the organization and each member then connects with their own Sandworld account. To stay anonymous, choose **No sign-in** instead: Claude connects from Anthropic's cloud, so the anonymous limits are shared with every other Claude.ai user of the sandbox. Where your organization has **Request headers**, a key also works: choose **No sign-in** and add `Authorization` with the value `Bearer sw_live_…`.

### Claude Code

```bash
claude mcp add --transport http sandworld https://sandworld.dev/mcp
```

It starts in the anonymous sandbox. To use your workspace, ask for something that needs it (“show my Sandworld workspace”), then run `/mcp`, pick Sandworld and authenticate: your browser opens Sandworld's sign-in. Or use a key (add `--scope user` to use it in every project; the default is this project only):

```bash
claude mcp add --transport http sandworld https://sandworld.dev/mcp \
  --header "Authorization: Bearer $SANDWORLD_API_KEY"
```

### ChatGPT

1. On ChatGPT on the web, open **Plugins**, select **+**, then **Add custom MCP server**.
2. Name it _Sandworld_ and, under **Connection**, enter `https://sandworld.dev/mcp` as the **Server URL**.
3. Under authentication, choose **OAuth** to use your workspace, or **OAuth or no authentication (mixed)** to start anonymously and sign in when a workspace tool needs it. ChatGPT registers itself with Sandworld; there's no client ID to enter.
4. Tick **I understand and want to continue**, select **Create as a plugin**, and when ChatGPT asks, sign in to Sandworld, check that it sends you back to `chatgpt.com`, and click **Allow**.
5. Install the plugin, then type `@` in a chat and pick Sandworld.

ChatGPT can't send custom headers, so it's OAuth or the anonymous sandbox, whose limits are shared across ChatGPT's addresses. Workspaces still on the older apps flow add it under **Settings → Apps** (with developer mode on) and **Create**. Business, Enterprise and Edu workspaces get full custom MCP support. On Pro, OpenAI currently allows custom MCP servers read and fetch permissions only, so starting episodes and calling tools may be unavailable there.

### Codex

```bash
codex mcp add sandworld --url https://sandworld.dev/mcp
```

Codex saves it in `~/.codex/config.toml`, which the Codex CLI, the IDE extension and the ChatGPT desktop app share (or put it in `.codex/config.toml` in a trusted project). When you add it, Codex checks whether the server supports sign-in and, if so, opens Sandworld's sign-in in your browser. Run `codex mcp login sandworld` to sign in at any time; Codex identifies itself to Sandworld, so there's no client ID to enter. Or use a key from your environment:

```toml
[mcp_servers.sandworld]
url = "https://sandworld.dev/mcp"
bearer_token_env_var = "SANDWORLD_API_KEY"
```

### Cursor

In `.cursor/mcp.json` in your project, or `~/.cursor/mcp.json` for every project:

```json
{
  "mcpServers": {
    "sandworld": {
      "url": "https://sandworld.dev/mcp"
    }
  }
}
```

With a key, add `"headers": { "Authorization": "Bearer ${env:SANDWORLD_API_KEY}" }`; Cursor reads the variable from your environment. Without a key, Cursor signs in with OAuth: it registers itself, and Sandworld accepts each of its callbacks, its loopback and web ones and its `cursor://anysphere.cursor-mcp/oauth/callback` app link, which the sign-in page shows as _Opens Cursor_.

### VS Code

Run **MCP: Add Server** from the Command Palette, choose **HTTP (HTTP or Server-Sent Events)**, enter `https://sandworld.dev/mcp` and the ID `sandworld`. Or add it to `.mcp.json` at the workspace root (shared), or `~/.copilot/mcp-config.json` (just you):

```json
{
  "mcpServers": {
    "sandworld": {
      "type": "http",
      "url": "https://sandworld.dev/mcp"
    }
  }
}
```

With a key, add `"headers": { "Authorization": "Bearer ${SANDWORLD_API_KEY}" }` in your personal file, not a shared one.

### OpenAI Agents SDK (Python)

```python
import asyncio, os
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

async def main():
    key = os.environ.get("SANDWORLD_API_KEY")  # optional
    async with MCPServerStreamableHttp(
        name="Sandworld",
        params={
            "url": "https://sandworld.dev/mcp",
            "headers": {"Authorization": f"Bearer {key}"} if key else {},
            "timeout": 30,
        },
        cache_tools_list=True,
    ) as sandworld:
        agent = Agent(
            name="Support agent",
            instructions="Use the Sandworld tools. Follow the environment's policy.",
            mcp_servers=[sandworld],
        )
        result = await Runner.run(agent, "Start Quickbasket task qb-01, do what the customer asks, then submit it.")
        print(result.final_output)

asyncio.run(main())
```

### How sign-in works (OAuth)

Sandworld follows the [MCP authorization spec](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization) (OAuth 2.1). When an app connects, Sandworld shows the app's name, the address it will send you back to and what it's asking for, under your account and workspace. Nothing is shared until you click **Allow**. The app can then:

- `environments`: See the worlds, including your workspace's private worlds, and your workspace's plan and limits.
- `episodes`: Start, step and submit episodes. They are recorded to your workspace and count against its limits.
- `evals`: Start baseline eval runs and read your workspace's eval runs and results.

Apps ask for all three when you sign in. One that asks for nothing in particular gets `environments` and `episodes`, an API key's default scopes, and is asked to add `evals` when a tool needs it. It never sees your password, API keys, billing or data projects. Its access tokens last an hour and are refreshed in the background; disconnect it any time under [Connected apps](https://sandworld.dev/app/connections), which ends its tokens at once.

For client developers:

- Protected resource metadata: `https://sandworld.dev/.well-known/oauth-protected-resource/mcp` (and at the root). Calling a workspace tool without a token gets a `401` whose `WWW-Authenticate` names it and the scopes to ask for; a token without a scope a tool needs gets a `403` with `error="insufficient_scope"`.
- Authorization server metadata: `https://sandworld.dev/.well-known/oauth-authorization-server`. Authorization code with PKCE `S256` only; `resource` is `https://sandworld.dev/mcp`; the response carries `iss` (RFC 9207).
- Two ways to identify your app. A **Client ID Metadata Document**(`client_id_metadata_document_supported`): use the https URL of your metadata document as the `client_id`. Sandworld fetches it when a signed-in user opens the sign-in page: https (port 443 or 8443), public addresses only, no redirects, 5 KB and 3 seconds at most, cached for its `max-age` (1 minute to 1 hour). Its `client_id` must equal the URL, it's a public client (`token_endpoint_auth_method` `none`), and its https redirect URIs must be on its own host. The sign-in page names that host. Or **dynamic client registration** at `/oauth/register`.
- Redirect URIs: https; http on a loopback address (any port); or, for a native app registered as a public client, its own scheme named after its domain in reverse, like `com.example.app:/callback` (RFC 8252). The sign-in page then says which app it opens. Every other scheme is refused.
- Tokens are opaque and valid only on `/mcp`, not on the REST API. Refresh tokens rotate on every use, and reusing an old one ends the connection. Revoke at `/oauth/revoke`.

## Tools it provides

| Tool | What it does |
| --- | --- |
| `list_environments` | Lists the app twins. |
| `describe_environment` | Policy, tools and tasks for one twin. |
| `list_tasks` | Public tasks with how often the published models solve them. Optional filters: environment, suite (v1, hard or all), model, pass_min and pass_max (0 to 1, inclusive), and limit (default 50). |
| `start_episode` | Starts a task (or free play) and returns the instruction, policy and tools. Optional user_style for how the simulated user phrases its replies, and variant for the same world under different names, so a memorised answer fails (see the API reference: variants). |
| `call_tool` | Runs one environment tool inside the episode and returns the observation. |
| `get_episode` | The episode's status, every call made so far and, once submitted, the verdict. |
| `submit_episode` | Closes the episode and returns every verifier check. |

Then ask: _“Start Quickbasket task qb-10, handle the customer's request according to the policy, and submit it.”_ The model reads the policy, looks up the order, declines the out-of-window refund and submits — and the verifier tells you whether it was right.

### Tasks by difficulty

`list_tasks` is [GET /api/v1/tasks](https://sandworld.dev/docs/api#tasks-by-difficulty) as a tool, with the same filters and the same errors, open to everyone like `list_environments`. Each task comes with its world, title, suites and a difficulty summary: the authored difficulty, the band, every published model pooled (`any_model`) and, when you name a `model`, that model's own pass rate. The result also says how many tasks match (`total`) and lists the published models by slug. Most published runs have one seed, so one model's rate on a task is 0 or 1, and a band in between comes from pooling the models. Try: _“List the tasks some published models solve and others don't”_ or _“Which Bench Hard tasks does gemini-3.5-flash-lite fail?”_

```text
{ "pass_min": 0.01, "pass_max": 0.99, "limit": 20 }
{ "suite": "hard", "model": "gemini-3.5-flash-lite", "pass_max": 0 }
```

### User styles

On tasks where the agent can ask the user (`ask_user`), `start_episode` takes a `user_style`: `default`, `impatient`, `vague` or `skeptical`. It changes how the simulated user phrases its replies, never what it knows, and the result names any style but the default. It's checked as the [episode API](https://sandworld.dev/docs/api#user-styles) checks it: anything else is an error, and `terse` and `non-native` are refused because they need an LLM-played user, which only the HTTP API starts (`"user_simulator": "llm"`).

```text
{ "environment": "quickbasket", "task_id": "qb-16", "seed": 1, "user_style": "vague" }
```

### Workspace tools

On the remote server, signed in (or with an API key that has the scope), these act on your own workspace. Called without an account, they ask you to sign in.

Episodes on your private worlds run on the same runtime as every other world: start one with `start_private_episode`, then use `call_tool`, `get_episode` and `submit_episode` with its episode id. Only tasks that passed _check my task_ start. The episode belongs to your workspace: for anyone else, and without an account, it doesn't exist, and nor does the world. Try: _“List my private worlds, start the first ready task on my clinic twin and solve it.”_

| Tool | What it does | Scope |
| --- | --- | --- |
| `get_workspace` | Your workspace, its plan, limits and usage this month. Ask for it to sign in. | `environments` |
| `list_private_worlds` | Your private worlds from the twin builder, with how many tasks are ready. | `environments` |
| `describe_private_world` | Policy, tools and ready tasks for one of your private worlds. | `environments` |
| `start_private_episode` | Starts a task (or free play) on one of your private worlds; then call_tool and submit_episode as for any world. Pro and Team. | `episodes` |
| `list_evals` | Your workspace's recent eval runs, from the app, CI or here. | `evals` |
| `get_eval` | One run: progress, pass rate and every task × seed with its failure reason. | `evals` |
| `start_eval` | Runs a baseline (oracle, random or null) on a public or private world. Model runs start from the app or CI, so your model key never passes through a chat. | `evals` |

## Run it locally (stdio)

For clients that start a local command instead of connecting by URL, `sandworld-mcp.mjs` serves the same tools over stdio. It calls Sandworld's HTTP API at `https://sandworld.dev/api/v1` unless you point it elsewhere, so it works as soon as it's added. It isn't a public download yet, because it's built from Sandworld's private source: [ask us for it](https://sandworld.dev/contact?intent=licence) with a licence or pilot.

### Claude Code

```bash
claude mcp add sandworld \
  --env SANDWORLD_API_KEY=sw_live_… \
  -- node /path/to/sandworld-mcp.mjs
```

### Claude Desktop

```json
{
  "mcpServers": {
    "sandworld": {
      "command": "node",
      "args": ["/path/to/sandworld-mcp.mjs"],
      "env": { "SANDWORLD_API_KEY": "sw_live_…" }
    }
  }
}
```

### Environment variables

- `SANDWORLD_API_KEY` — optional; without it the server uses the anonymous sandbox.
- `SANDWORLD_API_URL` — optional; the API it calls, `https://sandworld.dev/api/v1` by default (the same variable and default as the [Python client](https://sandworld.dev/docs#from-python) and `sw`). Set it to use another Sandworld server, such as a [lab image](https://sandworld.dev/docs/exports) delivered with a licence: `SANDWORLD_API_URL=http://localhost:8000`. A bare host gets `/api/v1` added.
