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

# Agent payments

> Let agents buy E2B sandboxes per request with stablecoins over the Machine Payments Protocol. No E2B account or API key.

`https://mpp.e2b.dev` sells E2B sandboxes over the [Machine Payments Protocol](https://mpp.dev) (MPP). An agent with a funded wallet creates, pauses, resumes, and kills sandboxes and pays for each request in stablecoins on [Tempo](https://tempo.xyz). There is no signup, no API key, and no monthly plan.

Use it when the caller is an autonomous agent that holds its own wallet, or when you want to pay for sandboxes per use without an E2B team.

## How it works

1. The agent sends a normal E2B API request, for example `POST /sandboxes`.
2. The proxy answers `402 Payment Required` with the exact price in the `WWW-Authenticate` header.
3. An MPP client signs the payment from the wallet and sends the request again.
4. The proxy settles the payment, forwards the request to E2B, and returns E2B's response.

E2B receives payments into a wallet managed by [Privy](https://privy.io).

Each sandbox belongs to the wallet that paid for it. Listing returns only your sandboxes, and any other wallet gets `404` for them.

Once a sandbox exists, working inside it is free: commands, files, and network traffic go straight to the sandbox, not through the proxy. You pay only for compute time and lifecycle calls.

## Check the price

Every route quotes its price before you pay. The 402 response names the template's spec and the requested time in `description`, and carries the amount in `request` (base64url JSON, \$1 = `1000000`):

```bash theme={"theme":"css-variables"}
quote=$(curl -si -X POST https://mpp.e2b.dev/sandboxes \
  -H 'content-type: application/json' \
  -d '{"templateID":"base","timeout":300}')
echo "$quote" | grep -o 'description="[^"]*"' | head -1
echo "$quote" | grep -o 'request="[^"]*"' | head -1 | cut -d'"' -f2 \
  | jq -rR 'gsub("-";"+") | gsub("_";"/") | @base64d | fromjson | "$\(.amount | tonumber / 1e6)"'
```

```text theme={"theme":"css-variables"}
description="Create sandbox - 2 vCPU, 512 MiB, 300s"
$0.008721
```

## Set up a wallet and pay

Pick how you want to hold the wallet. Both pay on Tempo mainnet, and gas is sponsored, so the wallet needs no other token.

> [tab] Tempo Wallet (browser)
>
> [Tempo Wallet](https://wallet.tempo.xyz) is Tempo's own wallet. You sign in with a passkey, buy MACH with a card, and give your agent a spending limit. The agent never holds the wallet's key, and you can see every payment it makes.
>
> MACH is an on-chain credit for paying approved merchants on Tempo, E2B included. \$1 buys 1 MACH, and it does not expire. It can only be spent, not withdrawn, sent to another wallet, or swapped.
>
> 1. Sign in at [wallet.tempo.xyz](https://wallet.tempo.xyz) and buy MACH on the [Balances](https://wallet.tempo.xyz/balances) page. Card checkout takes $5 to $100. \$5 buys hundreds of short sandboxes.
> 2. Connect your agent. In the agent's terminal, install the `tempo` CLI and log in:
>
>    ```bash theme={"theme":"css-variables"}
>    curl -fsSL https://tempo.xyz/install | bash
>    tempo wallet login
>    ```
>
>    It opens a link with a short code. Check the code matches, set the agent's spending limit, and approve. On a remote machine, add `--no-browser` and open the printed link yourself.
> 3. Check the price without paying. `--mach` selects a MACH charge, and `--max-spend` caps the payment in dollars:
>
>    ```bash theme={"theme":"css-variables"}
>    tempo request --dry-run --mach --max-spend 0.05 -X POST --json '{"templateID":"base","timeout":300}' \
>      https://mpp.e2b.dev/sandboxes
>    ```
> 4. Buy a `base` sandbox for 5 minutes in MACH by running the same command without `--dry-run`:
>
>    ```bash theme={"theme":"css-variables"}
>    tempo request --mach --max-spend 0.05 -X POST --json '{"templateID":"base","timeout":300}' \
>      https://mpp.e2b.dev/sandboxes
>    ```
> 5. List your sandboxes, then kill one. Replace `<sandboxID>` with the `sandboxID` from the create response:
>
>    ```bash theme={"theme":"css-variables"}
>    tempo request --mach --max-spend 0.05 https://mpp.e2b.dev/sandboxes
>    tempo request --mach --max-spend 0.05 -X DELETE https://mpp.e2b.dev/sandboxes/<sandboxID>
>    ```
>
> Or skip the commands: run `curl -fsSL https://tempo.xyz/skills/wallet/SKILL.md` and give it to Claude Code, Codex, or another agent, then ask it to buy an E2B sandbox from `https://mpp.e2b.dev`.
>
> Every payment shows up on the [Activity](https://wallet.tempo.xyz/activity) page, so you can follow what the agent spends without touching the terminal. MACH pays one-off charges only. For [sessions](#sessions), fund the wallet with USDC.e or OUSD instead.

> [tab] mppx (terminal)
>
> [mppx](https://github.com/wevm/mppx) keeps the wallet key on your machine. Use it for scripts, CI, and testing.
>
> 1. Install the CLI and create a wallet:
>
>    ```bash theme={"theme":"css-variables"}
>    npm i -g mppx
>    mppx account create -a agent --network mainnet
>    mppx account view -a agent
>    ```
> 2. Send USDC.e or OUSD on Tempo mainnet to the printed address.
> 3. Buy a `base` sandbox for 5 minutes. `mppx` pays the 402 and prints E2B's response:
>
>    ```bash theme={"theme":"css-variables"}
>    mppx https://mpp.e2b.dev/sandboxes -a agent \
>      -J '{"templateID":"base","timeout":300}'
>    ```
> 4. List your sandboxes, then kill one. Replace `<sandboxID>` with the `sandboxID` from the create response:
>
>    ```bash theme={"theme":"css-variables"}
>    mppx https://mpp.e2b.dev/sandboxes -a agent
>    mppx https://mpp.e2b.dev/sandboxes/<sandboxID> -X DELETE -a agent
>    ```

A successful create returns the sandbox ID and the token for reaching it:

```json theme={"theme":"css-variables"}
{"alias":"base","clientID":"6532622b","envdAccessToken":"1708...","envdVersion":"0.10.0","sandboxID":"iphajmqj713oe7yo1oyyw","templateID":"rki5dems9wqfm4r03t7g"}
```

Other MPP wallets work too. See [mpp.dev wallets](https://mpp.dev/tools/wallet).

## Run code in the sandbox

Pay for lifecycle calls with the `mppx` client, then attach the [E2B SDK](https://docs.e2b.dev/quickstart.md) to the new sandbox with the returned `envdAccessToken`. The SDK talks to the sandbox directly, so `commands`, `files`, and every other in-sandbox call are free.

The example below pays from an `mppx` wallet key. With Tempo Wallet, create the sandbox with `tempo request` instead and pass its `sandboxID`, `envdVersion`, and `envdAccessToken` to `new Sandbox(...)` the same way.

Save the code as `example.ts` and run it with `node example.ts` (Node 22.18 or later runs TypeScript directly):

```bash theme={"theme":"css-variables"}
npm i mppx viem e2b
export WALLET_PRIVATE_KEY="$(mppx account export -a agent)"
node example.ts
```

```typescript example.ts theme={"theme":"css-variables"}
import { Mppx, tempo } from 'mppx/client'
import { privateKeyToAccount } from 'viem/accounts'
import { Sandbox } from 'e2b'

const BASE_URL = 'https://mpp.e2b.dev'

// Pays every 402 from the wallet. No E2B account or API key is involved.
const mppx = Mppx.create({
  methods: [tempo({ account: privateKeyToAccount(process.env.WALLET_PRIVATE_KEY as `0x${string}`) })],
  polyfill: false,
})

async function call(method: string, path: string, body?: unknown) {
  const res = await mppx.fetch(`${BASE_URL}${path}`, {
    method,
    headers: body ? { 'content-type': 'application/json' } : undefined,
    body: body ? JSON.stringify(body) : undefined,
  })
  if (!res.ok) throw new Error(`${method} ${path}: ${res.status} ${await res.text()}`)
  return res.status === 204 ? undefined : res.json()
}

// 1. Buy 5 minutes of the `code-interpreter-v1` template.
const created = await call('POST', '/sandboxes', { templateID: 'code-interpreter-v1', timeout: 300 })

// 2. Attach the E2B SDK with the returned access token and run code. Not metered.
const sandbox = new Sandbox({
  sandboxId: created.sandboxID,
  envdVersion: created.envdVersion,
  envdAccessToken: created.envdAccessToken,
})
const result = await sandbox.commands.run('python3 -c "print(6 * 7)"')
console.log(result.stdout) // 42

// 3. Pause, then resume for another 5 minutes.
await call('POST', `/sandboxes/${created.sandboxID}/pause`)
await call('POST', `/sandboxes/${created.sandboxID}/connect`, { timeout: 300 })

// 4. Kill it when done.
await call('DELETE', `/sandboxes/${created.sandboxID}`)
```

> [!NOTE]
>
> Resuming with `connect` takes several payment rounds: the wallet first proves it owns the sandbox, then pays the quote. The `mppx` library client handles this. The one-shot `mppx <url>` CLI retries only once, so use the library for `connect`, `timeout`, and `refreshes`.

## Pricing

Prices follow [e2b.dev/pricing](https://e2b.dev/pricing), paid in dollar-pegged stablecoins (1 token = $1), with a 5% launch discount on compute and a flat $0.0001 on every request.

```
(vCPU × $0.000014 + GiB RAM × $0.0000045) × requested seconds × 0.95 + $0.0001
```

* **Compute is billed up front for the requested time.** Asking for 300 seconds costs 300 seconds, even if you kill the sandbox after 5. Request only what you need and extend with `timeout` or `refreshes`.
* **vCPU and RAM come from the template.** The only variable you control is the duration.
* **Pausing costs only the flat fee.** Unused paid time is not refunded or kept, and resuming a paused sandbox buys the requested time again.

For example, a `base` sandbox (2 vCPU, 512 MiB) costs $0.001824 for 1 minute and $0.008721 for 5 minutes.

## Endpoints

| Route | Price | What it does |
| - | - | - |
| `POST /sandboxes` | Compute + \$0.0001 | Create a sandbox for `timeout` seconds |
| `GET /sandboxes` | \$0.0001 | List your sandboxes |
| `GET /sandboxes/:id` | \$0.0001 | Get sandbox details |
| `DELETE /sandboxes/:id` | \$0.0001 | Kill a sandbox |
| `POST /sandboxes/:id/pause` | \$0.0001 | Pause a sandbox |
| `POST /sandboxes/:id/connect` | $0.0001 if running; compute + $0.0001 if paused | Get connection details, or resume a paused sandbox for `timeout` seconds |
| `POST /sandboxes/:id/timeout` | Compute + \$0.0001 | Set the sandbox timeout |
| `POST /sandboxes/:id/refreshes` | Compute + \$0.0001 | Extend the sandbox by `duration` seconds |
| `GET /sandboxes/:id/logs` | \$0.0001 | Get sandbox logs |
| `GET /sandboxes/:id/metrics` | \$0.0001 | Get sandbox metrics |

Request and response bodies match the [E2B REST API](https://docs.e2b.dev/api-reference/sandboxes/create-sandbox.md). The machine-readable spec is at [`/openapi.json`](https://mpp.e2b.dev/openapi.json). The maximum timeout is 24 hours.

## Templates

`templateID` accepts E2B's public templates: `base`, `code-interpreter-v1`, `desktop`, `claude`, `codex`, `amp`, `opencode`, and `openclaw`. The 402 for a create names the template's vCPU and RAM next to the price.

## Sessions

Every route also accepts [MPP sessions](https://mpp.dev/payment-methods/tempo/session). The agent deposits once into a payment channel, then pays each request with a signed voucher instead of an on-chain transfer. Prices are the same as one-off charges, and closing the channel returns the unused deposit.

```bash theme={"theme":"css-variables"}
mppx https://mpp.e2b.dev/sandboxes -a agent --session new -M deposit=0.05 -H "Accept-Payment: tempo/session"
mppx sessions close <channel-id> --url https://mpp.e2b.dev/sandboxes -a agent
```

`-M deposit=0.05` locks $0.05 in the channel. Without it, the server suggests a $1 deposit. Replace `<channel-id>` with the channel ID the first command prints.

## Limitations

* Only the public templates above. Custom templates, snapshots, and volumes are not available.
* `autoResume` is rejected. Resume a paused sandbox with a paid `connect`.
* `network` rules cannot use `${e2b.secrets.*}` or `${e2b.identity.tokens.*}` placeholders.
* The E2B SDK's own `Sandbox.create` cannot pay. Create sandboxes over HTTP as shown above, then attach the SDK.
