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

# Services

> Manage public URLs for sandbox ports with the TypeScript SDK.

Cloud-only (Available only on microsandbox cloud; the local backend throws UnsupportedError.)

See [Services](https://docs.microsandbox.dev/sandboxes/services.md) for usage and limits.

## Service

Properties use the last response without making a request.

Static methods

#### Service.builder()

```typescript theme={null}
static builder(slug: string): ServiceBuilder
```

> [accordion] Example
>
> ```typescript theme={null}
> import { Service } from "microsandbox";
>
> const svc = await Service.builder("my-app").target("my-sandbox", 8080).create();
> console.log(svc.url);
> ```

Start a [`ServiceBuilder`](#servicebuilder).

Parameters

`slug`stringService slug, e.g. `"my-app"`.

Returns

[ServiceBuilder](#servicebuilder)Builder for the new Service.

#### Service.get()

```typescript theme={null}
static get(slug: string): Promise<Service>
```

Get a Service by slug.

Parameters

`slug`stringService slug.

Returns

[Promise\<Service>](#service)The Service's current state.

#### Service.list()

```typescript theme={null}
static list(): Promise<ServicePage>
```

List the first page in slug order, including disabled and detached Services.

Returns

[Promise\<ServicePage>](#servicepage)One page of Services.

#### Service.listWith()

```typescript theme={null}
static listWith(
  configure: (list: ServiceListBuilder) => ServiceListBuilder,
): Promise<ServicePage>
```

> [accordion] Example
>
> ```typescript theme={null}
> import { Service } from "microsandbox";
>
> const page = await Service.listWith((l) => l.sandbox("my-sandbox").limit(50));
> for (const svc of page.services) {
>   console.log(svc.url, svc.target);
> }
> ```

List a configured page in slug order. A limit outside 1 through 100 throws `RangeError` before any request.

Parameters

`configure`(list: ServiceListBuilder) => ServiceListBuilderSets the [list options](#servicelistbuilder).

Returns

[Promise\<ServicePage>](#servicepage)One page of Services.

Instance properties

#### svc.slug

`string`

The Service slug.

#### svc.url

`string`

The public URL as returned by the backend.

#### svc.status

[`ServiceStatus`](#servicestatus)

Whether the Service routes requests, is disabled, or has no target, as of the read that returned this value. `refresh()` returns a current copy.

#### svc.target

[`ServiceTarget`](#servicetarget) ` | null`

The target, or `null` when the Service is detached.

#### svc.createdAt

`Date`

The creation time.

#### svc.updatedAt

`Date`

The last state-change time.

Instance methods

#### svc.update()

```typescript theme={null}
update(options: ServiceUpdateOptions): Promise<Service>
```

> [accordion] Example
>
> ```typescript theme={null}
> import { Service } from "microsandbox";
>
> let svc = await Service.get("my-app");
> svc = await svc.update({
>   target: { sandbox: "new-sandbox", port: 8080 },
> });
> ```

Change the target without retrying. If `changed` is `"unknown"`, get and check the Service.

Parameters

`options`[ServiceUpdateOptions](#serviceupdateoptions)Required target for the change.

Returns

[Promise\<Service>](#service)The Service as committed.

#### svc.enable()

```typescript theme={null}
enable(): Promise<Service>
```

Enable the Service without retrying. To enable a detached Service, set a running target with `update()` instead.

#### svc.disable()

```typescript theme={null}
disable(): Promise<Service>
```

Disable the Service without retrying while retaining its target.

#### svc.remove()

```typescript theme={null}
remove(): Promise<void>
```

Remove the Service and release its slug without retrying.

#### svc.refresh()

```typescript theme={null}
refresh(): Promise<Service>
```

Get the Service again and return its current state. This value is not changed.

Returns

[Promise\<Service>](#service)The Service's current state.

## ServiceBuilder

#### builder.target()

```typescript theme={null}
target(sandbox: string, port: number): this
```

Set the running sandbox and port that receive requests.

Parameters

`sandbox`stringTarget sandbox name.

`port`numberSandbox port, 1 through 65535.

#### builder.create()

```typescript theme={null}
create(): Promise<Service>
```

Create the Service without retrying. A port that is not an integer from 1 through 65535 throws `RangeError`; a missing target throws `InvalidConfigError`. Both errors occur before any request. Repeating a create with the same slug and target returns the existing Service while it is enabled.

Returns

[Promise\<Service>](#service)The Service as committed.

## ServiceUpdateOptions

Options for one target update. The target is required. A port that is not an integer from 1 through 65535 throws `RangeError` before any request.

#### target

```typescript theme={null}
target: ServiceTarget
```

Set the running target. This also enables or reattaches the Service. See [`ServiceTarget`](#servicetarget) for its fields.

## ServiceListBuilder

#### l.sandbox()

```typescript theme={null}
sandbox(name: string): this
```

Filter by target sandbox. An unknown name returns an empty page.

Parameters

`name`stringSandbox name.

#### l.limit()

```typescript theme={null}
limit(limit: number): this
```

Set the page size from 1 to 100; the default is 20.

Parameters

`limit`numberPage size.

#### l.cursor()

```typescript theme={null}
cursor(cursor: string): this
```

Continue from a previous `nextCursor`.

Parameters

`cursor`stringOpaque cursor.

## ServicePage

`services`[Service\[\]](#service)Services in this page, in slug order.

`nextCursor`string | undefinedCursor for the next page, or `undefined` on the final page.

## ServiceStatus

```typescript theme={null}
type ServiceStatus = "enabled" | "disabled" | "detached" | "unknown"
```

`"enabled"` routes requests, `"disabled"` retains the target without routing, `"detached"` has no target, and `"unknown"` represents an unrecognized backend value.

## ServiceTarget

`sandbox`stringCurrent name of the target sandbox.

`port`numberSandbox port that receives requests.

## ServiceError

A refused Service change or an unknown outcome. A missing Service throws `ServiceNotFoundError`, an unavailable slug throws `ServiceAlreadyExistsError`, and a missing target sandbox throws `SandboxNotFoundError`. Every `MicrosandboxError` from create, update, enable, disable, or remove exposes `changed`; it is `"unknown"` when the change may have been applied.

`slug`stringService slug.

`reason`ServiceErrorReasonReason for the failure.

`retryAfterMs`number | nullRetry delay returned with the refusal, in milliseconds, or `null`.

`changed`"unchanged" | "unknown"`"unknown"` means the change may have been applied; get and check the Service.

`rawCode`string | nullRaw refusal code when `reason` is `"other"`.

`rawStatus`number | nullHTTP status when `reason` is `"other"`.

`rawMessage`string | nullRaw refusal message when `reason` is `"other"`.

Reasons

`"serviceQuotaExceeded"`The organization's Service limit was reached. Remove a Service or request a higher limit.

`"sandboxServiceLimitExceeded"`The target sandbox's Service limit was reached. Remove or move a Service, or request a higher limit.

`"serviceConflict"`Another change to the Service committed first. Get it, then retry.

`"serviceDetached"`The Service is detached. Set a target.

`"targetUnreachable"`The target sandbox cannot be reached right now. Retry later, after `retryAfterMs` when set.

`"sandboxNotRunning"`The target sandbox is not running. Start it, then retry.

`"serviceChangesPaused"`Service changes are paused. Retry later, after `retryAfterMs` when set.

`"outcomeUnknown"`The change may have been applied. Get and check the Service before retrying.

`"other"`A reason this SDK does not recognize; `rawCode`, `rawStatus`, and `rawMessage` preserve the refusal, and `changed` still reports the outcome.

## ChangeState

```typescript theme={null}
type ChangeState = "unchanged" | "unknown"
```

`"unchanged"`Nothing changed.

`"unknown"`The change may have been applied. Get and check the Service before retrying.


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