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

# Read logs

> Fetch an instance's boot and runtime logs from your backend to debug a container that will not start or crashed after booting.

`GET /v1/instances/{id}/logs` returns a snapshot of the container's own output, everything the entrypoint and the agent printed to stdout and stderr, plus a compact health readout. It is how you debug an instance that crashed after booting, or your own [custom image](https://www.agent37.com/docs/agents-api/custom-image.md) that will not come up.

Call it on `https://sandbox.agent37.app`, with the same `sk_live_` key sent as the `X-Agent37-Key` header, the same way you call [chat](https://www.agent37.com/docs/agents-api/chat.md) and [files](https://www.agent37.com/docs/agents-api/files.md) on your instance URL. The request goes to the machine that holds the log file, so it answers much faster than it used to. The original address, `https://api.agent37.com/v1/instances/{id}/logs` with `Authorization: Bearer`, keeps working and returns the same logs, so existing code needs no change; it forwards to the address above. A request turned away there before it reaches the machine (a bad key, an instance that is not yours) gets a flat [transport error](https://www.agent37.com/docs/agents-api/errors.md#transport-errors) such as `{"error": "not_found"}` instead of the `{"error": {"code": ...}}` envelope. If your workspace has a [custom domain](https://www.agent37.com/docs/agents-api/domains.md), `https://sandbox.{yourdomain}` serves the same endpoint. Reading logs never wakes a [sleeping](https://www.agent37.com/docs/agents-api/instance-auto-sleep.md) instance.

Unlike [exec](https://www.agent37.com/docs/agents-api/exec.md), which needs a `running` container, logs works in **any** state: `running`, `sleeping`, `stopped`, or `failed`. That is the point. When a container will not stay up, exec has nothing to attach to, but its logs are still there. The one gap is an instance that slept so long it was parked off its host: its logs read empty until a wake brings it back.

> [!NOTE]
>
> A container that never got created at all (a bad image reference, or an `exec format error` from a wrong-architecture image) has no logs to show: `logs` is empty and `health` is `null`. The reason for that kind of failure lands in `status_reason` on the instance object, so fetch `GET /v1/instances/{id}` and read it. Logs cover the case where a container **did** start and then misbehaved.

## Request

**tail** `integer` (default: 500)

How many of the most recent log lines to return. Defaults to 500, capped at 2000 (a larger value is clamped down). A value that is not a positive integer returns `400 invalid_request`.

## Response

**logs** `string`

The container's combined stdout and stderr, most recent `tail` lines. Capped at 512 KB; see `truncated`. Empty when there is no container.

**truncated** `boolean`

`true` when the output spilled past the 512 KB cap and the oldest lines were dropped.

**health** `object | null`

A compact runtime readout, or `null` when there is no container. It answers "did it crash, and why."

**health**

**running** `boolean`

Whether the container is currently up.

**restart\_count** `integer`

How many times the container has booted beyond its first start. Wakes from [auto-sleep](https://www.agent37.com/docs/agents-api/instance-auto-sleep.md) count too, so a rising number on a sleeper is normal; a count that climbs while the instance never sleeps is a crash loop.

**exit\_code** `integer | null`

The last exit code when the runtime still has one, `null` otherwise. Expect `null` in most cases: crash evidence lives in `logs`, `restart_count`, and `resource_verdict`.

**oom\_suspected** `boolean`

Best-effort inference that the container was killed for exceeding its memory limit. `resource_verdict.memory` at `"critical"` is the reliable version of the same signal. If either fires, [resize](https://www.agent37.com/docs/agents-api/instances/resize.md) to a larger shape.

**resource\_verdict** `object | null`

Per-dimension pressure (`memory`, `cpu`, `disk`, and `overall`, each `healthy`, `pressure`, or `critical`), or `null` when the container is not running. `memory` reads `"critical"` after the instance has been killed for exceeding its memory limit.

**fetched\_at** `integer`

When the snapshot was taken, in epoch seconds.

Unknown, deleted, or other-workspace ids return `404 not_found`. If the platform cannot reach the instance's host, you get `502 provisioning_failed`.

## Example

```bash curl wrap theme={null}
curl -X GET \
  https://sandbox.agent37.app/v1/instances/ab12cd34ef/logs \
  --url-query "tail=200" \
  -H "X-Agent37-Key: sk_live_..."
```

```python Python wrap theme={null}
import requests

response = requests.get(
    "https://sandbox.agent37.app/v1/instances/ab12cd34ef/logs",
    headers={
        "X-Agent37-Key": "sk_live_..."
    },
    params={
        "tail": 200
    },
)
response.raise_for_status()
print(response.json())
```

```javascript Node wrap theme={null}
const query = new URLSearchParams({
  "tail": "200"
});

const response = await fetch(
  "https://sandbox.agent37.app/v1/instances/ab12cd34ef/logs" + "?" + query,
  {
    method: "GET",
    headers: {
      "X-Agent37-Key": "sk_live_..."
    },
  },
);
if (!response.ok) {
  throw new Error(await response.text());
}
console.log(await response.json());
```

```json response wrap theme={null}
{
  "logs": "[agent37-hermes] Booting (gateway_port=3737 ...)\n[agent37-hermes] Starting hermes gateway daemon...\n",
  "truncated": false,
  "health": {
    "running": true,
    "restart_count": 0,
    "exit_code": null,
    "oom_suspected": false,
    "resource_verdict": { "memory": "healthy", "cpu": "healthy", "disk": "healthy", "overall": "healthy" }
  },
  "fetched_at": 1781222420
}
```

## Debugging a failed instance

When an instance is `failed` or stuck, logs and `health` together tell you which layer broke:

* **The image will not start** (a climbing `restart_count`, with the same error at the top of `logs` on every boot): read the entrypoint's own error. This is the usual signal for a [custom image](https://www.agent37.com/docs/agents-api/custom-image.md) mistake, such as a missing binary, an entrypoint that exits, or a service that never listens on `default_port`.
* **It ran out of memory** (`resource_verdict.memory` is `"critical"`): the agent needs a bigger box. [Resize](https://www.agent37.com/docs/agents-api/instances/resize.md) to a larger shape.
* **It booted but the agent is wedged**: the logs show the last thing it did before it stopped responding. [Restart](https://www.agent37.com/docs/agents-api/instances/restart.md) to recover it.

Once you have a `running` container, drop into it with [exec](https://www.agent37.com/docs/agents-api/exec.md) to inspect further.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.