# Execute a command

Run a Bash command in a World. The request answers as soon as the command finishes or needs an approval, so most commands return their result here; one that still runs after 30 seconds answers with status running. Reuse a session to preserve files, the working directory, and shell state.

`POST https://api.smallworld.sh/api/v1/worlds/:worldId/execute`

## Parameters

| Name | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| worldId | path | UUID | Yes | The World ID shown in the dashboard. |
| command | body | string | Yes | Non-empty Bash source, at most 262144 UTF-8 bytes, with no null bytes. |
| userId | body | string | Yes | Your application's user ID. Required, also with sessionId, which must belong to this user. |
| sessionId | body | UUID | No | An existing session in this World. Omit to create a new session. |
| groupId | body | string | No | Your application's group ID: the group a new session acts for. Optional for a user with no group or one group, and required when the user belongs to several groups. With sessionId it isn't needed; if sent, it must be the session's group. null is invalid. |
| context | body | object | No | Optional JSON object, at most 4096 bytes when serialized. Forwarded to this execution's custom integration calls; never shown to the agent, and stored only while the execution is parked waiting for an approval. |
| files | body | array | No | Upload up to 100 files totaling 8 MiB decoded. Each entry has path (an absolute path under /workspace), content, and optional encoding (utf8 or base64, default utf8), persistInSession (default false), and sessionOnly (default false). Uploads replace files at their paths before the command runs. |
| fileChanges | body | string | No | Which changes execution.fileChanges returns: all (the default) for every file the command created, modified, or deleted under /workspace, uploaded for the uploaded paths only, or none for null. |
| wait | body | number | No | Seconds the request is held for the command to finish or need an approval, 0 to 30. Defaults to 30. Send less to get the execution ID while the command still runs; keep your client timeout above the wait. |

## Request examples

### curl

```curl
curl --fail-with-body -X POST 'https://api.smallworld.sh/api/v1/worlds/01995e56-e2d4-7f19-b691-7bf9af6abdc8/execute' \
  -H "Authorization: Bearer $SMALLWORLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "userId": "customer_123",
  "command": "echo '\''Hello from Smallworld'\''"
}'
```

### typescript

```typescript
const response = await fetch("https://api.smallworld.sh/api/v1/worlds/01995e56-e2d4-7f19-b691-7bf9af6abdc8/execute", {
  method: "POST",
  headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({
  "userId": "customer_123",
  "command": "echo 'Hello from Smallworld'"
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();
```

### python

```python
response = requests.post(
    "https://api.smallworld.sh/api/v1/worlds/01995e56-e2d4-7f19-b691-7bf9af6abdc8/execute",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
  "userId": "customer_123",
  "command": "echo 'Hello from Smallworld'"
},
    timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Responses

Returns toolCalls, user, session, created flags, and execution. execution.status is requires_approval, running, completed, timed_out, or interrupted. stdout and stderr are null while the command runs; each is cut at 1 MiB, and truncated says whether either was cut. errorCode names a failure the platform settled, such as execution_result_not_saved, and is otherwise null. fileChanges lists the files the command created, modified, or deleted under /workspace; it is null while the command runs, when the request set fileChanges to none, when the command's file changes were discarded (errorCode execution_file_changes_discarded), and for executions recorded before file changes were saved. Mount files never appear in fileChanges: mountChanges lists, for each mount the command changed, its mountId and path, outcome (saved or discarded), reason (why its changes weren't saved, or null), toolCallId (the check of those changes, or null), and changes, each with operation (create, update, delete, move, or rename), kind (file or directory), path or from and to, files for a folder's contents, and replaces for a move or rename onto an existing entry; mountChanges is null when the command changed no mount and while it runs. exitCode and completedAt may be null. session.userId is your application's user ID. session.groupId is your ID for the group the session acts for, or null in a groupless session; it stays after the group is deleted. session.status is idle, running, or closed, and session.closedReason is group_membership_removed, group_deleted, or null. user.groupIds is the user's current membership, also on an execution read later. created records whether this request created the user and session; read responses set both to false. outputFiles lists the files explicitly selected by view, including immutable authenticated content paths, or null when output was not captured.

### 200 · Completed

The command finished. Check exitCode as well as stdout, stderr, and toolCalls; completed can have a nonzero exit code.

```json
{
  "toolCalls": [],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": null,
    "status": "idle",
    "closedReason": null,
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": true,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "echo 'Hello from Smallworld'",
    "status": "completed",
    "stdout": "Hello from Smallworld\n",
    "stderr": "",
    "truncated": false,
    "exitCode": 0,
    "errorCode": null,
    "fileChanges": [],
    "outputFiles": [],
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Running

The command is still running. Output is null; retain the IDs and read the execution again.

```json
{
  "toolCalls": [],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": null,
    "status": "running",
    "closedReason": null,
    "stateVersion": 0,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "created": {
    "user": true,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "echo 'Hello from Smallworld'",
    "status": "running",
    "stdout": null,
    "stderr": null,
    "truncated": false,
    "exitCode": null,
    "errorCode": null,
    "fileChanges": null,
    "outputFiles": null,
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": null
  }
}
```

### 200 · Requires approval

The command paused at a pending tool invocation. Decide that exact toolCall, then read this execution again.

```json
{
  "toolCalls": [
    {
      "id": "b5212df0-ea8b-4eb8-a7b1-057ff45b3044",
      "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
      "executionId": "01995e57-3027-7557-a233-009ea3dcd8fc",
      "userId": "customer_123",
      "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
      "integration": "acme",
      "integrationName": "Acme",
      "account": null,
      "connectionSource": "none",
      "group": null,
      "toolName": "get_order",
      "toolDescription": "Read an order by its ID.",
      "toolLabel": "read",
      "arguments": {
        "orderId": "order_456"
      },
      "status": "pending",
      "result": null,
      "error": null,
      "errorCode": null,
      "reason": null,
      "providerApproval": null,
      "hooks": [],
      "createdAt": "2026-10-10T12:00:00.000Z",
      "expiresAt": "2026-10-10T12:15:00.000Z",
      "completedAt": null,
      "decidedAt": null
    }
  ],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": null,
    "status": "running",
    "closedReason": null,
    "stateVersion": 0,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "created": {
    "user": true,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "acme get-order --json '{\"orderId\":\"order_456\"}'",
    "status": "requires_approval",
    "stdout": null,
    "stderr": null,
    "truncated": false,
    "exitCode": null,
    "errorCode": null,
    "fileChanges": null,
    "outputFiles": null,
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": null
  }
}
```

### 200 · Timed out

The command reached the workspace's active-time limit (60 seconds by default) or the one-hour execution limit, and stopped with exit code 124. Approval waits pause both limits; integration calls count only toward the one-hour limit. stderr ends with the reason. Output printed before the timeout may be missing.

```json
{
  "toolCalls": [],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": null,
    "status": "idle",
    "closedReason": null,
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": true,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "sleep 120",
    "status": "timed_out",
    "stdout": "",
    "stderr": "Command timed out after 1 minute of active time, the limit for this workspace. Waiting for approvals and integration calls doesn't count toward it.\n",
    "truncated": false,
    "exitCode": 124,
    "errorCode": null,
    "fileChanges": [],
    "outputFiles": [],
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Interrupted

The command could not finish, such as after an API crash or shutdown while it ran, or its result couldn't be saved (errorCode execution_result_not_saved), or it behaved differently when it continued after a long approval wait (errorCode execution_replay_diverged). Its file changes were discarded. A command also ends interrupted when its session is closed because the user left the session's group or the group was deleted (errorCode session_closed). Inspect tool-call history before retrying external writes.

```json
{
  "toolCalls": [],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": null,
    "status": "idle",
    "closedReason": null,
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": true,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "echo 'Hello from Smallworld'",
    "status": "interrupted",
    "stdout": "",
    "stderr": "This command's result couldn't be saved, so its file changes were discarded. Check whether it had other effects before running it again.",
    "truncated": false,
    "exitCode": null,
    "errorCode": "execution_result_not_saved",
    "fileChanges": null,
    "outputFiles": null,
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Provider approval

The provider requested a choice for this pending call. Display the saved prompt and its choices to the acting user.

```json
{
  "toolCalls": [
    {
      "id": "b5212df0-ea8b-4eb8-a7b1-057ff45b3044",
      "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
      "executionId": "01995e57-3027-7557-a233-009ea3dcd8fc",
      "userId": "customer_123",
      "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
      "integration": "gmail",
      "integrationName": "Gmail",
      "account": "support@example.com",
      "connectionSource": "group",
      "group": {
        "id": "team_42",
        "name": "Support team"
      },
      "toolName": "trash_thread",
      "toolDescription": "Move a conversation to Trash.",
      "toolLabel": "destructive",
      "arguments": {
        "threadId": "thread_456"
      },
      "status": "pending",
      "result": null,
      "error": null,
      "errorCode": null,
      "reason": null,
      "providerApproval": {
        "id": "69b8aa84-bcbd-4f8b-833c-f414760d9449",
        "message": "This operation requires your permission.",
        "question": "Allow this operation?",
        "choices": [
          {
            "value": "ALLOW_ONCE",
            "label": "Allow once"
          },
          {
            "value": "DENY_ONCE",
            "label": "Deny once"
          }
        ]
      },
      "hooks": [],
      "createdAt": "2026-10-10T12:00:00.000Z",
      "expiresAt": "2026-10-10T12:15:00.000Z",
      "completedAt": null,
      "decidedAt": null
    }
  ],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [
      "team_42"
    ],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": "team_42",
    "status": "running",
    "closedReason": null,
    "stateVersion": 0,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "created": {
    "user": false,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "acme get-order --json '{\"orderId\":\"order_456\"}'",
    "status": "requires_approval",
    "stdout": null,
    "stderr": null,
    "truncated": false,
    "exitCode": null,
    "errorCode": null,
    "fileChanges": null,
    "outputFiles": null,
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": null
  }
}
```

### 200 · Selected file

The command selected an unchanged invoice page for display. Fetch contentPath with the same API key to read the saved PNG.

```json
{
  "toolCalls": [],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": null,
    "status": "idle",
    "closedReason": null,
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": true,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "view --as image --pages 2 invoice.pdf",
    "status": "completed",
    "stdout": "",
    "stderr": "",
    "truncated": false,
    "exitCode": 0,
    "errorCode": null,
    "fileChanges": [],
    "outputFiles": [
      {
        "id": "909e0ae1-f9c7-4a58-af88-c3e23e13707f",
        "kind": "image",
        "filename": "invoice-page-2.png",
        "mimeType": "image/png",
        "sizeBytes": 62742,
        "source": {
          "path": "/workspace/invoice.pdf",
          "page": 2
        },
        "width": 1224,
        "height": 1584,
        "contentPath": "/api/v1/executions/01995e57-3027-7557-a233-009ea3dcd8fc/outputs/909e0ae1-f9c7-4a58-af88-c3e23e13707f/content"
      }
    ],
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · File changes

The request uploaded memory.md without persistInSession. fileChanges returns its final content to save in your application, a report the command generated, and a session file it deleted, sorted by path. memory.md is not kept in the session.

```json
{
  "toolCalls": [],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": null,
    "status": "idle",
    "closedReason": null,
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": true,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "printf '\\nPrefers concise answers.\\n' >> memory.md && printf 'month,total\\n2026-09,42\\n' > report.csv && rm draft.md",
    "status": "completed",
    "stdout": "",
    "stderr": "",
    "truncated": false,
    "exitCode": 0,
    "errorCode": null,
    "fileChanges": [
      {
        "path": "/workspace/draft.md",
        "operation": "deleted",
        "uploaded": false
      },
      {
        "path": "/workspace/memory.md",
        "operation": "modified",
        "uploaded": true,
        "encoding": "utf8",
        "content": "Works on Smallworld.\n\nPrefers concise answers.\n"
      },
      {
        "path": "/workspace/report.csv",
        "operation": "created",
        "uploaded": false,
        "encoding": "utf8",
        "content": "month,total\n2026-09,42\n"
      }
    ],
    "outputFiles": [],
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Files discarded

The command's file changes couldn't be kept, here because /workspace can't hold symbolic links. The session keeps its previous files and none of the uploads, retained or not; fileChanges is null and errorCode is execution_file_changes_discarded.

```json
{
  "toolCalls": [],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": null,
    "status": "idle",
    "closedReason": null,
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": true,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "ln -s notes.md latest.md",
    "status": "completed",
    "stdout": "",
    "stderr": "This command's file changes were discarded because /workspace can't keep symbolic links (/workspace/latest.md).\n",
    "truncated": false,
    "exitCode": 1,
    "errorCode": "execution_file_changes_discarded",
    "fileChanges": null,
    "outputFiles": null,
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Mount changes

The command edited a file in the group's mount at /workspace/docs, whose update setting is ask. Someone approved the check in toolCalls, so mountChanges reports the mount's changes as saved. Mount files never appear in fileChanges; read their content through the mounts API.

```json
{
  "toolCalls": [
    {
      "id": "c3e1a9f2-4b7d-4e8a-9f10-2a3b4c5d6e7f",
      "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
      "executionId": "01995e57-3027-7557-a233-009ea3dcd8fc",
      "userId": "customer_123",
      "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
      "integration": "mounts",
      "integrationName": "Mounts",
      "account": null,
      "connectionSource": "none",
      "group": {
        "id": "team_42",
        "name": "Support team"
      },
      "toolName": "0199a1c4-5b6e-7a10-9c2d-3e4f5a6b7c8d",
      "toolDescription": "/workspace/docs — Product documentation. Answers to customer questions go in faq.md.",
      "toolLabel": "write",
      "arguments": {
        "path": "/workspace/docs",
        "changes": [
          {
            "operation": "update",
            "kind": "file",
            "path": "/workspace/docs/faq.md",
            "size": 37,
            "diff": "--- /workspace/docs/faq.md\n+++ /workspace/docs/faq.md\n@@ -1,3 +1,3 @@\n # FAQ\n \n-Refunds take 5 business days.\n+Refunds take 3 business days.\n"
          }
        ]
      },
      "status": "completed",
      "result": {
        "saved": true
      },
      "error": null,
      "errorCode": null,
      "reason": null,
      "providerApproval": null,
      "hooks": [],
      "createdAt": "2026-10-10T12:00:00.000Z",
      "expiresAt": "2026-10-10T12:15:00.000Z",
      "completedAt": "2026-10-10T12:00:01.000Z",
      "decidedAt": "2026-10-10T12:00:01.000Z"
    }
  ],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [
      "team_42"
    ],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": "team_42",
    "status": "idle",
    "closedReason": null,
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": false,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "sed -i 's/5 business days/3 business days/' /workspace/docs/faq.md",
    "status": "completed",
    "stdout": "",
    "stderr": "",
    "truncated": false,
    "exitCode": 0,
    "errorCode": null,
    "fileChanges": [],
    "outputFiles": [],
    "mountChanges": [
      {
        "mountId": "0199a1c4-5b6e-7a10-9c2d-3e4f5a6b7c8d",
        "path": "/workspace/docs",
        "outcome": "saved",
        "reason": null,
        "toolCallId": "c3e1a9f2-4b7d-4e8a-9f10-2a3b4c5d6e7f",
        "changes": [
          {
            "operation": "update",
            "kind": "file",
            "path": "/workspace/docs/faq.md"
          }
        ]
      }
    ],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Mount changes discarded

Someone rejected the mount's changes. They weren't saved, stderr says why, and the exit code became 1. The session's /workspace files and other mounts are saved as usual.

```json
{
  "toolCalls": [
    {
      "id": "c3e1a9f2-4b7d-4e8a-9f10-2a3b4c5d6e7f",
      "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
      "executionId": "01995e57-3027-7557-a233-009ea3dcd8fc",
      "userId": "customer_123",
      "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
      "integration": "mounts",
      "integrationName": "Mounts",
      "account": null,
      "connectionSource": "none",
      "group": {
        "id": "team_42",
        "name": "Support team"
      },
      "toolName": "0199a1c4-5b6e-7a10-9c2d-3e4f5a6b7c8d",
      "toolDescription": "/workspace/docs — Product documentation. Answers to customer questions go in faq.md.",
      "toolLabel": "write",
      "arguments": {
        "path": "/workspace/docs",
        "changes": [
          {
            "operation": "update",
            "kind": "file",
            "path": "/workspace/docs/faq.md",
            "size": 37,
            "diff": "--- /workspace/docs/faq.md\n+++ /workspace/docs/faq.md\n@@ -1,3 +1,3 @@\n # FAQ\n \n-Refunds take 5 business days.\n+Refunds take 3 business days.\n"
          }
        ]
      },
      "status": "denied",
      "result": null,
      "error": "Tool call denied",
      "errorCode": null,
      "reason": null,
      "providerApproval": null,
      "hooks": [],
      "createdAt": "2026-10-10T12:00:00.000Z",
      "expiresAt": "2026-10-10T12:15:00.000Z",
      "completedAt": "2026-10-10T12:00:01.000Z",
      "decidedAt": "2026-10-10T12:00:01.000Z"
    }
  ],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [
      "team_42"
    ],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": "team_42",
    "status": "idle",
    "closedReason": null,
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": false,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "sed -i 's/5 business days/3 business days/' /workspace/docs/faq.md",
    "status": "completed",
    "stdout": "",
    "stderr": "Changes to /workspace/docs were not saved: a person rejected them.\n",
    "truncated": false,
    "exitCode": 1,
    "errorCode": null,
    "fileChanges": [],
    "outputFiles": [],
    "mountChanges": [
      {
        "mountId": "0199a1c4-5b6e-7a10-9c2d-3e4f5a6b7c8d",
        "path": "/workspace/docs",
        "outcome": "discarded",
        "reason": "a person rejected them",
        "toolCallId": "c3e1a9f2-4b7d-4e8a-9f10-2a3b4c5d6e7f",
        "changes": [
          {
            "operation": "update",
            "kind": "file",
            "path": "/workspace/docs/faq.md"
          }
        ]
      }
    ],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 200 · Session closed

The user was removed from the session's group while the command ran. The command was stopped at once, and the session is closed for good: session.status is closed, closedReason is group_membership_removed, and groupIds no longer lists the group. Start a new session for further commands.

```json
{
  "toolCalls": [],
  "user": {
    "id": "customer_123",
    "email": null,
    "groupIds": [],
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:00.000Z"
  },
  "session": {
    "id": "01995e57-0501-76b8-b797-5b24df5b307f",
    "worldId": "01995e56-e2d4-7f19-b691-7bf9af6abdc8",
    "userId": "customer_123",
    "groupId": "team_42",
    "status": "closed",
    "closedReason": "group_membership_removed",
    "stateVersion": 1,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "updatedAt": "2026-10-10T12:00:01.000Z"
  },
  "created": {
    "user": false,
    "session": true
  },
  "execution": {
    "id": "01995e57-3027-7557-a233-009ea3dcd8fc",
    "sessionId": "01995e57-0501-76b8-b797-5b24df5b307f",
    "command": "sleep 30",
    "status": "interrupted",
    "stdout": "",
    "stderr": "This session is closed because the user left its group or the group was deleted. Start a new session.",
    "truncated": false,
    "exitCode": null,
    "errorCode": "session_closed",
    "fileChanges": null,
    "outputFiles": null,
    "mountChanges": null,
    "createdAt": "2026-10-10T12:00:00.000Z",
    "completedAt": "2026-10-10T12:00:01.000Z"
  }
}
```

### 400

invalid_request: The body is invalid; the message names the problem. This includes unknown fields, a missing userId (required with sessionId too), groupId: null, invalid files entries such as a relative path, a duplicate path, or non-canonical base64, and a background job (`cmd &`), which is rejected before anything runs. execution_files_limit_exceeded: The uploads exceed 100 files or 8 MiB of decoded content, or /workspace with them would exceed 64 MiB or 10,000 files and directories. The message names the limit; nothing runs. group_required: The request creates a session for a user who belongs to several groups and has no groupId.

#### invalid_request

The body is invalid; the message names the problem. This includes unknown fields, a missing userId (required with sessionId too), groupId: null, invalid files entries such as a relative path, a duplicate path, or non-canonical base64, and a background job (`cmd &`), which is rejected before anything runs.

```json
{
  "statusCode": 400,
  "code": "invalid_request",
  "message": "userId is required when sessionId is sent"
}
```

#### execution_files_limit_exceeded

The uploads exceed 100 files or 8 MiB of decoded content, or /workspace with them would exceed 64 MiB or 10,000 files and directories. The message names the limit; nothing runs.

```json
{
  "statusCode": 400,
  "code": "execution_files_limit_exceeded",
  "message": "Upload at most 100 files per execution"
}
```

#### group_required

The request creates a session for a user who belongs to several groups and has no groupId.

```json
{
  "statusCode": 400,
  "code": "group_required",
  "message": "This user belongs to several groups. Send groupId to choose one."
}
```

### 401

authentication_required: The Authorization header is missing or empty. invalid_api_key: The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

#### authentication_required

The Authorization header is missing or empty.

```json
{
  "statusCode": 401,
  "code": "authentication_required",
  "message": "Authentication is required"
}
```

#### invalid_api_key

The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

```json
{
  "statusCode": 401,
  "code": "invalid_api_key",
  "message": "The API key is invalid or revoked"
}
```

### 403

ip_not_allowed: The request came from an address outside the workspace's IP allowlist.

#### ip_not_allowed

The request came from an address outside the workspace's IP allowlist.

```json
{
  "statusCode": 403,
  "code": "ip_not_allowed",
  "message": "The source IP address is not allowed by this account's security settings"
}
```

### 404

world_not_found: The World does not exist in your workspace. session_not_found: The supplied session does not exist in your workspace. user_not_found: The represented user does not exist in your workspace. group_not_found: groupId names a group that does not exist in your workspace. Nothing is created.

#### world_not_found

The World does not exist in your workspace.

```json
{
  "statusCode": 404,
  "code": "world_not_found",
  "message": "World not found"
}
```

#### session_not_found

The supplied session does not exist in your workspace.

```json
{
  "statusCode": 404,
  "code": "session_not_found",
  "message": "Session not found"
}
```

#### user_not_found

The represented user does not exist in your workspace.

```json
{
  "statusCode": 404,
  "code": "user_not_found",
  "message": "User not found"
}
```

#### group_not_found

groupId names a group that does not exist in your workspace. Nothing is created.

```json
{
  "statusCode": 404,
  "code": "group_not_found",
  "message": "Group not found"
}
```

### 409

session_user_mismatch: The supplied userId does not match the session's user. session_world_mismatch: The session belongs to another World. user_not_in_group: groupId names a group the user does not belong to. No session is created. A userId this request saw for the first time is still created, without groups. session_group_mismatch: sessionId and groupId were both sent, and the session acts for another group or for none. session_closed: The session is closed: the user left its group, or the group was deleted. Start a new session. session_busy: Wait for the current execution to finish, resolving any pending tool approvals, before sending another command in this session. execution_file_conflict: An uploaded path is a directory in the session, or would go inside a file. The message names the path; nothing runs.

#### session_user_mismatch

The supplied userId does not match the session's user.

```json
{
  "statusCode": 409,
  "code": "session_user_mismatch",
  "message": "Session does not belong to this user"
}
```

#### session_world_mismatch

The session belongs to another World.

```json
{
  "statusCode": 409,
  "code": "session_world_mismatch",
  "message": "Session does not belong to this world"
}
```

#### user_not_in_group

groupId names a group the user does not belong to. No session is created. A userId this request saw for the first time is still created, without groups.

```json
{
  "statusCode": 409,
  "code": "user_not_in_group",
  "message": "The user does not belong to this group"
}
```

#### session_group_mismatch

sessionId and groupId were both sent, and the session acts for another group or for none.

```json
{
  "statusCode": 409,
  "code": "session_group_mismatch",
  "message": "Session does not act for this group"
}
```

#### session_closed

The session is closed: the user left its group, or the group was deleted. Start a new session.

```json
{
  "statusCode": 409,
  "code": "session_closed",
  "message": "This session is closed because the user left its group or the group was deleted. Start a new session."
}
```

#### session_busy

Wait for the current execution to finish, resolving any pending tool approvals, before sending another command in this session.

```json
{
  "statusCode": 409,
  "code": "session_busy",
  "message": "Wait for the current execution to finish and resolve any pending approvals before sending another command."
}
```

#### execution_file_conflict

An uploaded path is a directory in the session, or would go inside a file. The message names the path; nothing runs.

```json
{
  "statusCode": 409,
  "code": "execution_file_conflict",
  "message": "/workspace/notes is a directory in this session"
}
```

### 413

request_too_large: The JSON body is larger than 12 MiB. File uploads count toward it, base64 or escaping included.

#### request_too_large

The JSON body is larger than 12 MiB. File uploads count toward it, base64 or escaping included.

```json
{
  "statusCode": 413,
  "code": "request_too_large",
  "message": "The request body is larger than 12 MiB."
}
```

### 415

unsupported_media_type: The request has a body that isn't JSON. Send JSON with Content-Type: application/json, or no body at all.

#### unsupported_media_type

The request has a body that isn't JSON. Send JSON with Content-Type: application/json, or no body at all.

```json
{
  "statusCode": 415,
  "code": "unsupported_media_type",
  "message": "Send the request body as JSON with Content-Type: application/json."
}
```

### 500

internal_error: An unexpected server error.

#### internal_error

An unexpected server error.

```json
{
  "statusCode": 500,
  "code": "internal_error",
  "message": "Internal server error"
}
```

## Notes

- Public user IDs are identifiers from your application, not Smallworld's internal database IDs. Derive them from your authenticated user on your backend.

- Omitting sessionId always creates a new session, even when this user already has sessions in this World. Store the returned session.id and reuse it for subsequent commands.

- Use view to read PDF text, select an image, or return a file. execution.outputFiles lists the selected images and downloads, including unchanged uploads. Fetch the bytes with the same API key at each entry's contentPath. See the Send and receive files guide for a complete example.

- An unknown userId is created automatically.

- A session acts for one user and at most one group, fixed when the session is created. A new session for a user with no groups is groupless: it uses personal and workspace-wide resources only, and stays groupless when the user joins a group later. A new session for a user with one group acts for that group. A user in several groups needs groupId. Requests for users with no group or one group need no groupId.

- A user with groups can't start a groupless session, so groupId: null is invalid. With sessionId, the session keeps its group; a groupId for another group returns session_group_mismatch.

- Inside a group session the user's own connection to an integration is used first, also when it needs reconnecting, then the connection of the session's group. The group's tool overrides and integration switches apply to every call in the session, whichever connection serves it. The session's mounts are the global ones, those of the session's group, and the user's own. Two groups can therefore have different accounts for the same integration and different mounts at the same path.

- A move (PUT /groups/:groupId/users/:userId, or POST /users with groupId) keeps sessions open: the user's open sessions that acted for the old group act for the new one. A closed session never reopens, also when the user rejoins the group; start a new session. The user's sessions for other groups are unaffected.

- Commands start immediately. The initial response waits up to one second for completion or an approval pause, so it may already contain output.

- An HTTP 200 does not guarantee a successful command. Check execution.status, exitCode, stdout, and stderr.

- When the user leaves the session's group, other than by a move, or the group is deleted, the session is closed for good: session.status is closed and session.closedReason says why. A running command is stopped at once and ends interrupted with errorCode session_closed. A command waiting for approval ends the same way, and its pending tool call ends interrupted with errorCode session_closed. Executions, tool calls, and outputs stay readable.

- Poll GET /executions/:executionId while the command is running or requires_approval. For each pending toolCall, render providerApproval.choices when providerApproval is present and submit the selected value through /tool-approvals/:id/provider/:approvalId. Otherwise use /tool-approvals/:id/approve or /deny.

- A tool call marked unknown may have reached its remote service. Check the remote result before retrying a write.

- Changes to a mount are checked once per mount at the end of the command. When they need approval, the execution is requires_approval and toolCalls includes the pending check, with integration mounts and the mount's ID as toolName; decide it like any tool call.

- When a mount's changes aren't saved, stderr gets a notice such as `Changes to /workspace/docs were not saved: a person rejected them.` and an exit code of 0 becomes 1. The session's /workspace files and other mounts are still saved.

- Each fileChanges entry has path, operation (created, modified, or deleted), and uploaded, which is true for paths uploaded in this request. Created and modified entries include the final content and its encoding, never truncated. Uploaded paths are compared with the uploaded bytes and other paths with the session's files before the command, so an unchanged upload isn't listed and removing a non-retained upload is never a deletion. Directories, modification times, and permissions aren't reported.

- A retained upload becomes an ordinary session file, so later executions report its changes with uploaded false. A rename is a deletion plus a creation and a copy is a creation, also for non-retained uploads, which then persist at their new path. A non-retained upload over an existing file doesn't bring that file back. Directories created to hold an upload stay in the session, also when the upload itself isn't retained, and are never reported.

- To keep your own copy of a session's files, apply your uploads and every execution's fileChanges in order, then remove your non-retained uploads. If your application can change a file while a command runs, compare its revision before saving the returned content; Smallworld doesn't merge changes.

- There are no endpoints that read or write session files directly: upload files with an execution (the command can be true) and delete them with rm. Returned contents stay in the saved execution result, also for non-retained uploads.

- By default, an upload into a visible mount with persistInSession true writes directly to the mount. With persistInSession false only this command sees the upload. To keep attachments private to the session, set sessionOnly true. If a guarded path overlaps a mount at execution time, the execution is interrupted with errorCode execution_file_conflict before any upload is written.

- Only one command can run in a session at a time. Queue requests per session in your application.

- This endpoint has no idempotency parameter. Do not blindly repeat a POST after an ambiguous network failure.

- The World is a virtual terminal, not a host shell. The Overview's Terminal reference lists what persists between commands, what is supported, and the limits.
