# Bash

Let the model run bash commands in a sandbox through the Messages route, and pay for the seconds it runs.

1. [What it does](#1-what-it-does).
2. [Name it in `tools`](#2-name-it-in-tools).
3. [Read what it bills on](#3-read-what-it-bills-on).

This page is one helper. The list of helpers, and how the charge adds up, sit in [Helpers](/docs/helpers).

## 1. What it does

The model writes a bash command, OpenDunes runs it in a sandbox that belongs to your account, and the output goes back to the model. It reads the output, then runs another command or answers. Files a command writes stay in the sandbox, where you can read them.

| | |
|---|---|
| Type | `opendunes:bash` |
| Route | `/v1/messages` |
| A step | one command run |
| Steps | at most 30 a request |
| Bills on | each second of sandbox, in DA |

The helper works on `/v1/messages` and nowhere else. On `/v1/chat/completions` and `/v1/responses`, a request that names it is refused with a `400` and nothing runs; [Shell](/docs/shell) is the helper for `/v1/responses`.

## 2. Name it in `tools`

Souk Bot has the model print a short list for a shop's page. The sample allows five steps and prints the model's reply and the charge.

```python
import json
import os
import urllib.request

API_KEY = os.environ["OPENDUNES_API_KEY"]
ADDRESS = "https://opendunes.com/v1/messages"
MODEL = "anthropic/claude-sonnet-4.5"
PROMPT = "With a command, print the numbers 1 to 5 joined by commas."

body = {
    "model": MODEL,
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": PROMPT}],
    "tools": [{"type": "opendunes:bash"}],
    "max_tool_calls": 5,
}
request = urllib.request.Request(
    ADDRESS,
    data=json.dumps(body).encode(),
    headers={
        "Authorization": "Bearer " + API_KEY,
        "Content-Type": "application/json",
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)

for block in answer["content"]:
    if block["type"] == "text":
        print(block["text"])
print(answer["usage"]["cost"])
```

```javascript
const API_KEY = process.env.OPENDUNES_API_KEY;
const ADDRESS = "https://opendunes.com/v1/messages";
const MODEL = "anthropic/claude-sonnet-4.5";
const PROMPT = "With a command, print the numbers 1 to 5 joined by commas.";

const response = await fetch(ADDRESS, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: MODEL,
    max_tokens: 1024,
    messages: [{ role: "user", content: PROMPT }],
    tools: [{ type: "opendunes:bash" }],
    max_tool_calls: 5,
  }),
});
const answer = await response.json();

for (const block of answer.content) {
  if (block.type === "text") console.log(block.text);
}
console.log(answer.usage.cost);
```

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

const (
	address = "https://opendunes.com/v1/messages"
	model   = "anthropic/claude-sonnet-4.5"
	prompt  = "With a command, print the numbers 1 to 5 joined by commas."
)

func main() {
	apiKey := os.Getenv("OPENDUNES_API_KEY")
	body, err := json.Marshal(map[string]any{
		"model":      model,
		"max_tokens": 1024,
		"messages": []map[string]string{
			{"role": "user", "content": prompt},
		},
		"tools": []map[string]string{
			{"type": "opendunes:bash"},
		},
		"max_tool_calls": 5,
	})
	if err != nil {
		panic(err)
	}
	req, err := http.NewRequest("POST", address, bytes.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+apiKey)
	req.Header.Set("Content-Type", "application/json")
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	var answer struct {
		Content []struct {
			Type string `json:"type"`
			Text string `json:"text"`
		} `json:"content"`
		Usage struct {
			Cost json.Number `json:"cost"`
		} `json:"usage"`
	}
	if err := json.NewDecoder(res.Body).Decode(&answer); err != nil {
		panic(err)
	}
	for _, block := range answer.Content {
		if block.Type == "text" {
			fmt.Println(block.Text)
		}
	}
	fmt.Println(answer.Usage.Cost)
}
```

```bash cURL
ADDRESS="https://opendunes.com/v1/messages"
MODEL="anthropic/claude-sonnet-4.5"
PROMPT="With a command, print the numbers 1 to 5 joined by commas."

curl "$ADDRESS" \
  -H "Authorization: Bearer $OPENDUNES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL"'",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "'"$PROMPT"'"
      }
    ],
    "tools": [
      {
        "type": "opendunes:bash"
      }
    ],
    "max_tool_calls": 5
  }'
```

The answer is a `200`. The model's commands and their output are blocks in `content`, and you send none of them back. Name the helper by its type, `opendunes:bash`; any other spelling of the type is a `400`.

The files a command left are read without charge, with an API key: `GET /v1/containers/{id}/files` lists them, and `GET /v1/containers/{id}/files/{file}/content` returns one file's bytes. The sandbox's id comes back in the helper's result. [Sandbox files](/docs/reference/containers) shows both.

## 3. Read what it bills on

One charge, in DA, from your balance, the moment the answer ends: the model's tokens and the seconds the sandbox ran. `usage.cost` carries the whole of it. The Plugins tab of your dashboard's Gateway page lists the helper with its price.

A sandbox bills by the clock, not by the step, so a sandbox has a spend cap. Before the model starts, OpenDunes holds money from your wallet for the words and the answer, and writes the cap into the request.

| Your request | The hold |
|---|---|
| names no `stop_server_tools_when` | writes two conditions: the step count, 30 or your `max_tool_calls`, and a `max_cost` equal to half of what the wallet has left after the answer's hold; the helper stops at whichever comes first |
| names `stop_server_tools_when` with a `max_cost` | holds that cap whole; when the wallet cannot pay it, the answer is a `402` that says what the request needs |
| names `stop_server_tools_when` without a `max_cost` | keeps your conditions and adds the cap |

A cap is a condition on the request:

```json
{
  "stop_server_tools_when": [
    { "type": "step_count_is", "step_count": 8 },
    { "type": "max_cost", "max_cost_in_dollars": 0.05 }
  ]
}
```

When the steps or the cap run out, the model answers with what it has gathered.

<div class="dont">
<p>Don't let a command wait on something that may never finish. The sandbox bills each second until a step or the cap stops it.</p>
</div>

<div class="do">
<p>Name a <code>max_cost</code> when the task has a size you know, and keep <code>max_tool_calls</code> low.</p>
</div>
