# songstress/sandbox

> The globals an entry's code finds in the sandbox, for the compiler.

Page: https://songstress.app/docs/develop/reference/sandbox/

`songstress/sandbox` exports nothing to import: it declares the globals an entry's code finds in Songstress's
sandbox, and nothing more. Name it in your extension's `tsconfig.json`, and code that reaches for `fetch`,
`process`, `window` or `document` does not compile, which is the truth: they are not there. The way to the network
is `songstress.net.fetch`.

```json title="tsconfig.json"
{ "compilerOptions": { "lib": ["ES2023"], "types": ["songstress/sandbox"] } }
```

Each global, and every description, is read from the SDK's `sandbox.d.ts` when the site is built.

### Console

The extension's log: `songstress dev` prints it, and the server keeps the
last of it for its admin.

| Field | Type | Description |
|---|---|---|
| `log` | `(...data: unknown[]) => void` | Writes a line to the log. |
| `info` | `(...data: unknown[]) => void` | Writes a line to the log, as information. |
| `warn` | `(...data: unknown[]) => void` | Writes a line to the log, as a warning. |
| `error` | `(...data: unknown[]) => void` | Writes a line to the log, as an error. |
| `debug` | `(...data: unknown[]) => void` | Writes a line to the log, as detail for debugging. |

### console

The extension's log.

```ts
declare var console: Console
```

### setTimeout

Calls `handler` once, after `ms` milliseconds. A timer does not keep a
call alive past the promise its handler returned.

```ts
declare function setTimeout(handler: (...args: never[]) => void, ms?: number, ...args: unknown[]): number
```

| Parameter | Type | Description |
|---|---|---|
| `handler` | `(...args: never[]) => void` | What to call. |
| `ms?` | `number` | How long to wait, in milliseconds. |
| `...args` | `unknown[]` | What `handler` is called with. |

Returns `number`: The timer's id, for `clearTimeout`.

### setInterval

Calls `handler` every `ms` milliseconds, until `clearInterval`. Like every
timer, it does not keep a call alive past the promise its handler returned.

```ts
declare function setInterval(handler: (...args: never[]) => void, ms?: number, ...args: unknown[]): number
```

| Parameter | Type | Description |
|---|---|---|
| `handler` | `(...args: never[]) => void` | What to call. |
| `ms?` | `number` | How long between calls, in milliseconds. |
| `...args` | `unknown[]` | What `handler` is called with. |

Returns `number`: The timer's id, for `clearInterval`.

### clearTimeout

Stops a timer `setTimeout` set.

```ts
declare function clearTimeout(id: number | undefined): void
```

| Parameter | Type | Description |
|---|---|---|
| `id` | `number \| undefined` | The timer's id. |

Returns `void`.

### clearInterval

Stops a timer `setInterval` set.

```ts
declare function clearInterval(id: number | undefined): void
```

| Parameter | Type | Description |
|---|---|---|
| `id` | `number \| undefined` | The timer's id. |

Returns `void`.
