> ## 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 Python SDK.

Cloud-only (Available only on microsandbox cloud; the local backend raises 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.create()

```python theme={null}
async def create(slug: str, *, target: ServiceTarget) -> Service
```

> [accordion] Example
>
> ```python theme={null}
> from microsandbox import Service, ServiceTarget
>
> svc = await Service.create("my-app", target=ServiceTarget("my-sandbox", 8080))
> print(svc.url)
> ```

Create a Service for a running target without retrying. Port zero raises `InvalidConfigError` before any request. Repeating a create with the same slug and target returns the existing Service while it is enabled. Get and check the Service if the task is cancelled after the request is sent.

Parameters

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

`target`[ServiceTarget](#servicetarget)The running sandbox and port that receive requests. The port is 1 through 65535.

Returns

[Service](#service)The Service as committed.

#### Service.get()

```python theme={null}
async def get(slug: str) -> Service
```

Get a Service by slug.

Parameters

`slug`strService slug.

Returns

[Service](#service)The Service's current state.

#### Service.list()

```python theme={null}
async def list() -> ServicePage
```

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

Returns

[ServicePage](#servicepage)One page of Services.

#### Service.list\_with()

```python theme={null}
async def list_with(
    *,
    sandbox: str | None = None,
    cursor: str | None = None,
    limit: int | None = None,
) -> ServicePage
```

> [accordion] Example
>
> ```python theme={null}
> from microsandbox import Service
>
> page = await Service.list_with(sandbox="my-sandbox", limit=50)
> for svc in page.services:
>     print(svc.url, svc.target)
> ```

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

Parameters

`sandbox`str | NoneTarget sandbox; an unknown name returns an empty page.

`cursor`str | NoneA previous `next_cursor`.

`limit`int | NonePage size from 1 to 100; defaults to 20.

Returns

[ServicePage](#servicepage)One page of Services.

Instance properties

#### svc.slug

`str`

The Service slug.

#### svc.url

`str`

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) ` | None`

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

#### svc.created\_at

`float`

The creation time in milliseconds since epoch.

#### svc.updated\_at

`float`

The last state-change time in milliseconds since epoch.

Instance methods

#### svc.update()

```python theme={null}
async def update(
    *,
    target: ServiceTarget,
) -> Service
```

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

Change the target without retrying. `target` is required; `None` or port zero raises `InvalidConfigError` before any request. Get and check the Service if the task is cancelled after the request is sent.

Parameters

`target`[ServiceTarget](#servicetarget)Running target; also enables or reattaches the Service.

Returns

[Service](#service)The Service as committed.

#### svc.enable()

```python theme={null}
async def enable() -> Service
```

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

#### svc.disable()

```python theme={null}
async def disable() -> Service
```

Disable the Service without retrying while retaining its target.

#### svc.remove()

```python theme={null}
async def remove() -> None
```

Remove the Service and release its slug without retrying.

#### svc.refresh()

```python theme={null}
async def refresh() -> Service
```

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

Returns

[Service](#service)The Service's current state.

## ServiceStatus

`ServiceStatus.ENABLED`"enabled"Routes requests to its target.

`ServiceStatus.DISABLED`"disabled"Retains its target without routing requests.

`ServiceStatus.DETACHED`"detached"Has no target.

`ServiceStatus.UNKNOWN`"unknown"The backend returned an unrecognized status.

## ServiceTarget

```python theme={null}
ServiceTarget(sandbox: str, port: int)
```

A frozen dataclass; targets compare by value.

`sandbox`strCurrent name of the target sandbox.

`port`intSandbox port, 1 through 65535. A negative number or one above 65535 raises `OverflowError` before any request.

## ServicePage

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

`next_cursor`str | NoneCursor for the next page, or `None` on the final page.

## ServiceError

A refused Service change or an unknown outcome. A missing Service raises `ServiceNotFoundError`, an unavailable slug raises `ServiceAlreadyExistsError`, and a missing target sandbox raises `SandboxNotFoundError`.

Every exception raised by Service create, update, enable, disable, or remove carries `changed`, not only `ServiceError`: `MicrosandboxError.changed` is a [`ChangeState`](#changestate) for those calls and `None` for other calls.

`slug`strService slug.

`reason`[ServiceErrorReason](#serviceerrorreason)Reason for the failure.

`retry_after`float | NoneRetry delay returned with the refusal, in seconds, or `None`.

`changed`[ChangeState](#changestate)`ChangeState.UNKNOWN` means the change may have been applied; get and check the Service.

`raw_code`str | NoneRaw error code of a refusal with reason `OTHER`, or `None`.

`raw_status`int | NoneHTTP status of a refusal with reason `OTHER`, or `None`.

`raw_message`str | NoneMessage of a refusal with reason `OTHER`, or `None`.

## ServiceErrorReason

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

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

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

`SERVICE_DETACHED`The Service is detached. Set a target.

`TARGET_UNREACHABLE`The target sandbox cannot be reached right now. Retry later, after `retry_after` when set.

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

`SERVICE_CHANGES_PAUSED`Service changes are paused. Retry later, after `retry_after` when set.

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

`OTHER`A refusal this SDK does not recognize. `raw_code`, `raw_status`, and `raw_message` hold what was returned; `changed` still reports the outcome.

## ChangeState

`ChangeState.UNCHANGED`"unchanged"Nothing changed.

`ChangeState.UNKNOWN`"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.