# Shell Hosting, Lifespan & Strict CSP

> Use aiui.create_shell_app() when your product wants PraisonAIUI's React app shell, selected pages, plugin assets/routes, and custom endpoints without mounting t

Use `aiui.create_shell_app()` when your product wants PraisonAIUI's React app shell, selected pages, plugin assets/routes, and custom endpoints **without** mounting the general agent server surface (`/sessions`, `/run`, `/agents`, `/teams`, `/api/chat/*`, or the 48 backend agent features).

## Minimal shell host (`create_shell_app`)

```python
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.routing import Route

import praisonaiui as aiui
from my_plugin import plugin


async def health_extra(_request: Request) -> JSONResponse:
    return JSONResponse({"service": "my-product", "ok": True})


app = aiui.create_shell_app(
    plugins=[plugin],
    routes=[Route("/api/service/status", health_extra, methods=["GET"])],
    csp="strict",
    require_auth=False,
)
```

What `create_shell_app()` mounts:
- Your caller-supplied `routes` first.
- Health endpoints (`/health`, `/api/health`, `/health/live`, `/health/ready`), `/me`, and `POST /api/auth/ws-ticket` (plus `/login`, `/register`, `/logout` when auth is enabled).
- Shell manifest and assets (`/api/shell/manifest`, `/api/pages`, `/_aiui/externals/*`, `/assets/*`, `/plugins/*`, `/icon.svg`).
- Plugin routes (`/api/plugins/<name>/*`) and plugin static modules (`/_plugins/<name>/*`).
- SPA shell routes for **registered page IDs only** — unknown paths such as `/sessions` return `404`.

## Strict hash-based CSP without HTML parsing

Passing `csp="strict"` computes the exact `'sha256-…'` hashes of the shell's executable inline bootstrap scripts (never `'unsafe-inline'` in `script-src`) and attaches the `Content-Security-Policy` header automatically.

You can also merge extra directives or supply a custom builder using the exported helpers:

```python
import praisonaiui as aiui

# Option 1: merge extra directives onto STRICT_SHELL_CSP
app = aiui.create_shell_app(
    plugins=[plugin],
    csp={"img-src": ["'self'", "https://cdn.example.com"]},
)

# Option 2: custom callable receiving rendered HTML and exact sha256 script hashes
app = aiui.create_shell_app(
    plugins=[plugin],
    csp=lambda html, hashes: aiui.shell_csp_header(
        html,
        extra={"connect-src": ["'self'", "wss://ws.example.com"]},
    ),
)

# Option 3: standalone helpers if you render shell HTML inside an existing ASGI host
html, hashes = aiui.render_shell_html(style="app")
csp_header = aiui.shell_csp_header(html)
```

## Plugin ASGI `lifespan(app)` hook

Plugins that manage background workers, subprocesses, database pools, or PTY/WebSocket registries can define an async (or sync) `lifespan(app)` context manager. Both `create_app()` and `create_shell_app()` compose every active plugin's `lifespan` via `AsyncExitStack` (startup in registration order, shutdown in LIFO order, with per-plugin error isolation):

```python
from contextlib import asynccontextmanager
from typing import Any, AsyncIterator


class WorkerPlugin:
    name = "worker_ops"
    sdk = 1

    @asynccontextmanager
    async def lifespan(self, app: Any) -> AsyncIterator[None]:
        pool = await start_worker_pool()
        app.state.worker_pool = pool
        try:
            yield
        finally:
            await pool.close()
```

## Zero 404 console noise (`manifest.builtins`)

In a shell-only host (or when built-ins are disabled via `extensions.disabled`), the manifest includes an additive `builtins` summary:

```json
{
  "builtins": {
    "disabled": ["builtin.approvals"],
    "unmounted": ["builtin.notifications"]
  }
}
```

- Built-ins in `builtins.disabled` are skipped completely during browser activation (even `always: true` services).
- Built-ins in `builtins.unmounted` skip background server SSE/REST polling (`/api/approvals/stream`, `/api/notifications/stream`) while preserving client-only services such as `sdk.notifications.push(...)` and the header notification bell.
- If your host explicitly mounts `/api/notifications` in `create_shell_app(routes=[...])`, `builtin.notifications` is automatically removed from `unmounted` and reconnects to your endpoint.

## Related pages

- [Testing Plugins (`praisonaiui.testing`)](https://ui.praison.ai/docs/features/plugins/testing.md)
- [Compiled Site Hosting & Docs Inventory](https://ui.praison.ai/docs/features/plugins/site-hosting-and-inventory.md)
- [Workflows, Hooks & OpenAI-Compatible API](https://ui.praison.ai/docs/features/workflows-and-openai-api.md)
