# Workers & Static Sites

Run HTTP servers in isolated Nitro Sandboxes (Node, Python, or static Linux binaries) or serve static sites directly from CloudFront and S3.

A **Worker** is either a long-running HTTP server inside an AWS Nitro Sandbox or a **static site** served from S3 through CloudFront with zero compute and zero cold starts.

## Runtimes

| Runtime | Flag | Entry point | Notes |
| --- | --- | --- | --- |
| **Node** | `--runtime node` | `main` in `package.json` or `index.js` | Node LTS, listens on `PORT`, `NODE_ENV=production`. |
| **Python** | `--runtime python` | `main.py` at bundle root | Python 3.14, `PYTHONUNBUFFERED=1`, vendor deps in `.packages/` (`musllinux` wheels for `aarch64`). |
| **Static binary** | `--runtime binary` | Executable `main` at bundle root | Static `aarch64` Linux binary (e.g., Rust `aarch64-unknown-linux-musl` or Go `CGO_ENABLED=0 GOARCH=arm64`). |
| **Static site** | `--runtime static` | Built files at bundle root | Unpacked to S3 at deploy with Brotli/gzip copies; served via CloudFront. |

## Bundle Rules & Environment

- Archives (`.tar.gz`) can be up to **64 MiB** compressed (**512 MiB** and 100,000 entries unpacked).
- The bundle mounts read-only at `/app`. `/tmp` is a writable **1 GiB** scratch disk cleared on every cold start.
- The platform injects `PORT`, `MH_WORKER`, `MH_DEPLOYMENT`, `SKOPIK_BINDINGS_URL`, and `MH_BINDINGS_URL`.
- Precedence: **platform variables → Worker secrets → `.env` file in bundle**.

## Scaling, Memory & Warm Instances

Instances start on demand and stop after **5 minutes** of idle time (open streams and WebSockets keep an instance active). You can configure `memory_mib` (`256`, `512`, or `1024`; default `256`) and `min_instances` (`0` to `4`; default `0`) to keep `production` warm:

:::tabs
::tab skopik
```bash
skopik update_worker --worker api --memory-mib 512 --min-instances 1
```
::tab curl
```bash
curl -X PATCH https://api.platform.skopik.com/v1/workers/api \
  -H "Authorization: Bearer $SKOPIK_API_KEY" \
  -H "content-type: application/json" \
  -d '{"memory_mib": 512, "min_instances": 1}'
```
::tab MCP
```json
{
  "tool": "update_worker",
  "arguments": { "worker": "api", "memory_mib": 512, "min_instances": 1 }
}
```
:::

## Immutable Deployments, Aliases & Rollback

Every deploy creates an immutable deployment with its own URL. Named aliases (`production`, or preview aliases like `feat-login`) point at a deployment:

- **Deploy to a preview alias:** `skopik deploy --worker api --alias feat-login`
- **Instant rollback:** `skopik rollback --worker api` moves the alias back to its previous deployment.
- **CDN caching:** Worker responses with a cacheable `Cache-Control` header are cached at CloudFront automatically.

## Static Sites

Deploy a built frontend directory with `--runtime static`:

```bash
skopik deploy --dir dist --worker web --runtime static
```

Configure SPA routing, clean URLs, custom 404 pages, and per-path `Cache-Control` rules in `skopik.json`:

```json
{
  "static": {
    "spa": true,
    "clean_urls": true,
    "not_found": "404.html",
    "cache_control": [
      { "path": "/assets/*", "value": "public, max-age=31536000, immutable" }
    ]
  }
}
```

> [!NOTE]
> Static deployments cannot declare `bindings`, `mounts`, secrets, or crons. Files are pre-compressed with Brotli and gzip at deploy time and served directly from S3 through CloudFront.
