> For the list of every page, fetch /llms.txt. The API contract is the OpenAPI file linked from the API reference.

# Clients

Meadow has three clients on top of the HTTP API. All three cover models, sandboxes, images, projects, keys, and provider keys. The Go SDK and `mdw` also read usage.

| Client | Good for | Adds on top of the API |
| --- | --- | --- |
| Python client | Scripts, notebooks, eval harnesses | Sync and async, directory upload and download, follow a background command to the end |
| Go SDK | Services | The same helpers, with no dependencies outside the standard library |
| `mdw` CLI | Your terminal and shell scripts | `cp`, `ssh`, `exec` that exits with the remote exit code |

Next step: install the file your Meadow contact sent you, then run its example below. You do not need a client to use Meadow: every guide has curl samples, and [Quickstart](/get-started/quickstart), [Running commands](/run-sandboxes/running-commands), and [Files, ports, and SSH](/run-sandboxes/files-ports-and-ssh) have plain Python for the same calls.

## Install

During the private beta the clients are not on PyPI, a public Go module proxy, or a package manager, and there is no download page yet. Your Meadow contact sends you the files. Ask for the one you need.

| Client | What you receive | Install |
| --- | --- | --- |
| Python client | A wheel, `meadow-0.1.0-py3-none-any.whl` | `pip install ./meadow-0.1.0-py3-none-any.whl` |
| `mdw` CLI | One binary for your system | Put it on your `PATH`, then run `mdw --help` |
| Go SDK | The source of the `sdk/meadow` package | Add it to your module as your contact describes |

Do not run `pip install meadow`. That name on PyPI belongs to an unrelated project, and it installs something else. Install the wheel file by path.

To check the Python install:

```bash
python -c "import importlib.metadata as m, meadow; print(m.version('meadow'), meadow.Meadow)"
```

```text
0.1.0 <class 'meadow._client.Meadow'>
```

### Generate a client for another language

The OpenAPI file that ships with these docs is valid OpenAPI 3.1, and each operation's `operationId` is the method name a generator uses. We generated a Python client with `openapi-python-client`, installed it, and listed models on the hosted beta with it:

```bash
openapi-python-client generate --path openapi.yaml
pip install ./meadow-api-client
```

The generator skipped one operation, `createBuildContext`, because its body is a gzip stream. Send that one call yourself. Other generators were not tried.

## Set the address and the key

```bash
export MEADOW_BASE_URL="https://api.usemeadow.ai"
export MEADOW_API_KEY="mdw_..."
```

The key is required.

- The Python client, the Go SDK and `mdw` read both variables.
- `MEADOW_BASE_URL` is optional. Without it all three clients call `https://api.usemeadow.ai`. Set it, or pass the address to the client, to call another host. A build sent out between 2026-11-24 and the addition of this default does not start without it: see the [changelog](/reference/changelog).
- Each client sends its version in `User-Agent`: `meadow-python/<version>`, `meadow-go/<version>`, `mdw/<version>`. `mdw --version` prints it.
- You can pass them in code instead: `Meadow(api_key, base_url)` in Python, `meadow.WithAPIKey` and `meadow.WithBaseURL` in Go, `--base-url` on `mdw`.
- Client builds sent out before 2026-11-24 had a default address that is not the hosted beta. Replace them.

## What the clients do for you

- Retries. Every call is sent at most 3 times: the first try and 2 retries, as in the OpenAI SDKs. `max_retries` in Python and `WithMaxRetries` in Go change that. A 429 is retried for every call, model calls included, after the `retry-after` the server sent, or with exponential backoff and jitter when it sent none. A 5xx or a lost connection is retried only for calls that are safe to repeat. Running a command, writing stdin, creating a project, and creating a key are sent once on those failures. When a 503 with `error.code` `server_restarting` or `database_unavailable` carries `x-should-retry: true`, the clients send any call that is not a model call again, a command included.
- Model calls are retried on a 429 only. A 429 means no provider took the call. After a 5xx or a timeout a model call is never sent again: Meadow has already tried every provider in the route, a provider may have billed for the failed call, and each send counts against the key's limits. A stream that has started is never sent again. This rule is newer than the client builds sent out before 2026-11-24, which sent a model call once.
- Idempotency. A sandbox create carries one `Idempotency-Key` across its retries, so a retry cannot start a second sandbox.
- Dead connections. A connection can die without either side being told. The Go client and `mdw` check a quiet connection with an HTTP/2 ping after 45 seconds and drop it when no reply comes in 10 seconds. If you build your own Go transport, keep the ping at 30 seconds or slower: the hosted service closes a connection that pings every 25 seconds or faster, and that ends a long quiet call. A call that is safe to repeat is then sent again on a new connection. The Python client has no ping: it drops an idle connection after 5 seconds, and a call already sent on a dead connection waits for its read timeout (60 seconds for most calls, none for a stream). Do: set your own timeout around a Python stream. Go clients built without `WithHTTPClient` share one connection pool, so building a client per request does not open a connection per request. Clients with different API keys to the same host share one HTTP/2 connection as well. If that connection is closed, every call open on it ends, for every key, and the retry rules above apply to each call. To keep them apart, pass each client its own HTTP client built on `meadow.NewTransport()`. If you pass your own HTTP client, it is used as it is: in Go, give it `meadow.NewTransport()` as its transport.
- Broken model streams. A model stream that ends with an error event (see [Streaming](/call-models/streaming#after-the-first-event)) is an error in all three formats, never a clean finish. The Python client raises `meadow.ModelStreamError`, the Go client's `ModelStream.Err()` returns a `*meadow.ModelStreamError`, and `mdw models call --stream` prints the error with the request ID and exits 1. The clients do not send the call again.
- Waiting. `wait_running` (Python) and `WaitRunning` (Go) poll until the sandbox runs, and raise or return an error when it ends as `failed`.
- Background commands. `run_background` (Python), `RunBackground` (Go), and `mdw exec --background --follow` start a command and read it by offset until it ends. A dropped connection loses no output.
- Directories. `upload_dir` and `download_dir` pack and unpack the tar for you. Downloads treat the archive as untrusted: links are skipped unless you opt in, and an entry that would land outside the target folder is rejected.
- Delete. Returns nothing when the sandbox is gone, and the sandbox in `terminating` when the provider is slow.

One gap: the blocking exec result in the Python client and the Go SDK has no `stdout_truncated` or `stderr_truncated` field. If a command may print more than 4 MiB, run it in the background or write to a file. See [Output caps](/run-sandboxes/running-commands#output-caps-and-the-truncated-flags).

## Python

Needs Python 3.10 or newer. The example expects a `./task` directory that holds a `run.py`.

```python
from meadow import Meadow

with Meadow() as client:  # reads MEADOW_API_KEY and MEADOW_BASE_URL
    sandbox = client.sandboxes.create(
        image="python:3.12-slim",
        timeout_seconds=600,
        labels={"team": "docs"},
    )
    try:
        sandbox = client.sandboxes.wait_running(sandbox.id)
        print("running on", sandbox.provider)

        client.sandboxes.upload_dir(sandbox.id, "./task", "/work")
        result = client.sandboxes.exec(sandbox.id, ["python", "run.py"], cwd="/work")
        print("blocking:", result.exit_code, result.stdout.strip())

        run = client.sandboxes.run_background(
            sandbox.id,
            "for i in 1 2 3; do echo step $i; sleep 1; done; echo finished > /work/result.txt",
            on_stdout=lambda text: print("background:", text, end=""),
        )
        print("background:", run.status, run.exit_code)

        result_file = client.sandboxes.download_file(sandbox.id, "/work/result.txt")
        print("result.txt:", result_file.decode().strip())
    finally:
        client.sandboxes.delete(sandbox.id)
```

Output from a run against the hosted beta, which took 10 seconds:

```text
running on daytona
blocking: 0 hello from run.py
background: step 1
background: step 2
background: step 3
background: exited 0
result.txt: finished
```

`AsyncMeadow` has the same groups and methods as coroutines. The methods of each group in version 0.1.0:

| Group | Methods |
| --- | --- |
| `client.models` | `list`, `chat_completions`, `responses`, `messages`, `stream_chat_completions`, `stream_responses`, `stream_messages` |
| `client.sandboxes` | `create`, `get`, `list`, `iter`, `update_network`, `delete`, `wait_running`, `exec`, `exec_stream`, `exec_background`, `run_background`, `follow_exec`, `get_exec`, `kill_exec`, `write_exec_stdin`, `upload_file`, `download_file`, `upload_dir`, `download_dir`, `upload_tar`, `download_tar`, `port`, `ssh` |
| `client.images` | `create`, `get`, `list`, `iter`, `delete`, `wait`, `build_from_dir`, `create_build_context`, `upload_build_context_dir` |
| `client.projects` | `create`, `get`, `list`, `update`, `delete` |
| `client.keys` | `create`, `list`, `get`, `current`, `update`, `revoke` |
| `client.provider_keys` | `put`, `list`, `delete` |

Only the methods in the example above were run for this page. `help(client.sandboxes.exec)` shows the arguments of a method.

Errors:

| Error | When |
| --- | --- |
| `meadow.APIError` | The API answered with an error. It carries the status code and the error body. Branch on `status_code` and `code`. On a model route `type` is the provider's string, such as `rate_limit_error`: see [Errors](/reference/errors#errors-on-model-routes). |
| `meadow.SandboxNotRunningError` | `wait_running` saw the sandbox end before it ran. `.sandbox` holds the last state, with `attempts`. |
| `meadow.ImageBuildError` | A build failed while you waited for it. |
| `meadow.StreamError` | A stream ended before it was complete. |
| `meadow.ModelStreamError` | A model stream ended with an error event: the provider's stream broke, or the server restarted. Raised while you iterate, after the events that arrived. It carries `request_id`, `type`, `code` and `message`. |

`create(wait=True)` returns the sandbox whatever its status. Check `status`, or call `wait_running` as the example does.

## Go

The import path is `github.com/polymath-ai-labs/meadow/sdk/meadow`.

```go
package main

import (
	"context"
	"fmt"
	"io"
	"log"
	"os"

	"github.com/polymath-ai-labs/meadow/sdk/meadow"
)

func run(ctx context.Context) error {
	client, err := meadow.NewClient()
	if err != nil {
		return err
	}

	sandbox, err := client.Sandboxes.Create(ctx, meadow.SandboxCreate{
		Image:          "python:3.12-slim",
		TimeoutSeconds: 600,
		Labels:         map[string]string{"team": "docs"},
	}, meadow.SandboxCreateOptions{})
	if err != nil {
		return err
	}
	defer func() {
		if _, err := client.Sandboxes.Delete(context.WithoutCancel(ctx), sandbox.ID); err != nil {
			log.Print(err)
		}
	}()

	sandbox, err = client.Sandboxes.WaitRunning(ctx, sandbox.ID, meadow.WaitOptions{})
	if err != nil {
		return err
	}
	fmt.Println("running on", sandbox.Provider)

	if err := client.Sandboxes.UploadDir(ctx, sandbox.ID, "./task", "/work"); err != nil {
		return err
	}
	result, err := client.Sandboxes.Exec(ctx, sandbox.ID, meadow.ExecRequest{
		Command: meadow.Argv("python", "run.py"),
		Cwd:     "/work",
	})
	if err != nil {
		return err
	}
	fmt.Printf("blocking: %d %s", result.ExitCode, result.Stdout)

	background, err := client.Sandboxes.RunBackground(ctx, sandbox.ID,
		meadow.ExecRequest{Command: meadow.Shell("for i in 1 2 3; do echo step $i; sleep 1; done; echo finished > /work/result.txt")},
		meadow.FollowOptions{Stdout: os.Stdout, Stderr: os.Stderr})
	if err != nil {
		return err
	}
	if background.ExitCode == nil {
		return fmt.Errorf("the command was %s", background.Status)
	}
	fmt.Println("background:", background.Status, *background.ExitCode)

	file, err := client.Sandboxes.DownloadFile(ctx, sandbox.ID, "/work/result.txt")
	if err != nil {
		return err
	}
	defer file.Close()
	content, err := io.ReadAll(file)
	if err != nil {
		return err
	}
	fmt.Printf("result.txt: %s", content)
	return nil
}

func main() {
	if err := run(context.Background()); err != nil {
		log.Fatal(err)
	}
}
```

Output from a run against the hosted beta, which took 11 seconds:

```text
running on daytona
blocking: 0 hello from run.py
step 1
step 2
step 3
background: exited 0
result.txt: finished
```

- `meadow.Shell("...")` runs through `sh -c`. `meadow.Argv(...)` runs the list as given.
- An API error is a `*meadow.APIError` with `StatusCode`, `Type`, `Code`, `Message`, and `Attempts`. Branch on `StatusCode` and `Code`. On a model route `Type` is the provider's string, such as `rate_limit_error`: see [Errors](/reference/errors#errors-on-model-routes).
- `Sandboxes.Delete` returns `nil` when the sandbox is gone, and the sandbox in `terminating` when the provider is slow.
- `Sandboxes.UpdateNetwork(ctx, id, meadow.Network{...})` replaces the network rules of a running sandbox and returns it. Python has `client.sandboxes.update_network(sandbox_id, Network(...))`, and the CLI has `mdw sandboxes network SANDBOX_ID` with `--open`, `--block-network`, `--allow-domain` and `--allow-cidr`. All three send every field, so the whole rule set is replaced.
- The groups are `client.Models`, `client.Sandboxes`, `client.Images`, `client.Projects`, `client.Keys`, `client.Usage`, and `client.ProviderKeys`.

## The `mdw` CLI

Every command below ran against the hosted beta. The `mdw ssh` line ran on a second sandbox, created the same way. `./environment` holds a `Dockerfile` and the files it copies. `./task` holds `run.py`.

```bash
mdw images build ./environment --name cli-demo
```

```text
uploading ./environment and building
id      img_0000d1f8
name    cli-demo
sha256  0000000000000000000000000000000000000000000000000000000000003b26
build   daytona ready 0000b8c3
build   modal ready im-<id>
```

```bash
SANDBOX=$(mdw sandboxes create --image-id img_0000d1f8 --port 8000 --ssh --timeout 600 --label team=docs --json | jq -r .id)

mdw cp -r ./task "$SANDBOX":/work
mdw exec "$SANDBOX" --cwd /work -- "python run.py && exit 3"; echo "exit=$?"
```

```text
copied ./task to sbx_0000c884:/work
hello from run.py
exit=3
```

`mdw sandboxes create` waits until the sandbox runs. `mdw exec` exits with the remote command's exit code. One argument after `--` runs through `sh -c`. Several arguments run as given.

```bash
mdw exec "$SANDBOX" --stream -- "for i in 1 2 3; do echo line \$i; sleep 1; done"
mdw exec "$SANDBOX" --background --follow -- "for i in 1 2 3; do echo step \$i; sleep 1; done; echo finished > /work/result.txt"
mdw cp "$SANDBOX":/work/result.txt .
```

```text
line 1
line 2
line 3
started exec_00002d14
step 1
step 2
step 3
copied sbx_0000c884:/work/result.txt to result.txt
```

```bash
mdw ports "$SANDBOX" 8000
mdw ssh "$SANDBOX" -- -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=./known_hosts 'echo ssh ok; id -un'
mdw sandboxes delete "$SANDBOX"
mdw images delete img_0000d1f8
```

```text
url      https://8000-<id>.daytonaproxy01.net
header   X-Daytona-Preview-Token: <token>
expires  -
ssh ok
root
deleted sbx_0000c884
deleted img_0000d1f8
```

Notes:

- `--json` prints the API object on stdout and nothing else. Progress goes to stderr.
- `mdw cp -r ./task SANDBOX:/work` puts the contents of `./task` into `/work`. It does not create `/work/task`.
- `mdw ssh` writes the key to a temporary file, runs your local `ssh`, then removes the key. Arguments after `--` go to `ssh`: options first, then a remote command.
- On Daytona, `ssh` asks you to accept the host key the first time. In a script that has no terminal it fails with `Host key verification failed`, so the sample passes `-o StrictHostKeyChecking=accept-new`. On Modal the host key is pinned and there is no question.
- `mdw sandboxes delete` prints `deleted <id>`, or `terminating <id>` when the provider is slow. Both exit 0.

Other commands: `keys`, `projects`, `provider-keys`, `models`, `sandboxes list|get`, `execs get|kill|stdin`, `images list|get`, `usage`. Run `mdw <command> --help` for the flags.

`mdw mcp` runs a Model Context Protocol server for coding agents. See [MCP server](/get-started/mcp-server).

## API reference

The clients wrap every operation, except that the Python client has no usage methods yet. The example above uses [`createSandbox`](/reference/api-reference#createsandbox), [`getSandbox`](/reference/api-reference#getsandbox), [`uploadFile`](/reference/api-reference#uploadfile), [`execInSandbox`](/reference/api-reference#execinsandbox), [`getExec`](/reference/api-reference#getexec), [`downloadFile`](/reference/api-reference#downloadfile), and [`deleteSandbox`](/reference/api-reference#deletesandbox).