---
url: 'https://adk.nht.io/api/@nhtio/adk/batteries/functions/serveIsolated.md'
---

# Function: serveIsolated()

```ts
function serveIsolated<S>(
  spec: S,
  factory: IsolatedImplementationFactory<S>,
  options?: ServeIsolatedOptions,
): {
  stop: () => void;
};
```

Defined in: [src/batteries/isolation/serve.ts:330](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/isolation/serve.ts#L330)

Serve `spec` in the CURRENT environment, duck-detecting a Web Worker global scope
(`globalThis.self.postMessage`) or a node child\_process (`globalThis.process.send`) — in that
order — and building the matching [PortLike](../interfaces/PortLike.md) automatically. This module never imports any
`node:*` builtin, so it is safe to bundle for either target; the detection is a pure `globalThis`
duck check.

## Type Parameters

| Type Parameter                                                                                                                                                                                                     |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `S` *extends* [`IsolatedServiceSpec`](../interfaces/IsolatedServiceSpec.md)<[`MethodMap`](../type-aliases/MethodMap.md), [`StreamMap`](../type-aliases/StreamMap.md), [`EventMap`](../type-aliases/EventMap.md)> |

## Parameters

| Parameter  | Type                                                                                       |
| ---------- | ------------------------------------------------------------------------------------------ |
| `spec`     | `S`                                                                                        |
| `factory`  | [`IsolatedImplementationFactory`](../type-aliases/IsolatedImplementationFactory.md)<`S`> |
| `options?` | [`ServeIsolatedOptions`](../interfaces/ServeIsolatedOptions.md)                            |

## Returns

```ts
{
  stop: () => void;
}
```

| Name     | Type         | Defined in                                                                                                                        |
| -------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `stop()` | () => `void` | [src/batteries/isolation/serve.ts:334](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/isolation/serve.ts#L334) |

## Throws

@nhtio/adk/batteries/isolation!E\_ISOLATION\_UNSUPPORTED\_ENV when neither environment
is detected (e.g. called on a plain main-thread browser tab, or in a test with no fake `self`/
`process.send`) — use [serveIsolatedOverPort](serveIsolatedOverPort.md) directly there instead.
