# TypeScript Examples

## Prerequisites

- Node.js >= 22
- `msb` + `libkrunfw` available from the `microsandbox` platform package installed through optional dependencies, or `MSB_PATH` pointing at a working `msb` binary
- For `root-bind` and `root-block`: `git submodule update --init --recursive`

## Setup

Each example is a standalone Node.js project. Install dependencies first:

```sh
cd examples/typescript/<example>
npm install
```

## Running

```sh
npm start
```

For example:

```sh
cd examples/typescript/root-oci
npm install
npm start
```

Configuration-focused examples intentionally replace their fixed-name sandbox so reruns match the source. `shell-attach` uses `connectOrCreate` instead, preserving its interactive workspace and configuration across runs.

## Examples

| Example | Description |
|---------|-------------|
| `lifecycle-convergence` | Live convergence and stale-handle identity-safety checks with timing metrics |
| `cloud-backend` | Cloud backend lifecycle and live logs |
| `root-oci` | OCI image rootfs |
| `root-bind` | Bind-mounted local directory |
| `root-block` | qcow2 disk image |
| `rootfs-patch` | Pre-boot filesystem patches |
| `init-handoff` | Hand PID 1 off to systemd |
| `volume-named` | Named volumes shared across sandboxes |
| `volume-disk` | Disk image volumes (raw / qcow2) at guest paths |
| `snapshot-fork` | Snapshot a stopped sandbox and boot a fresh one from it |
| `fs-read-stream` | Streaming file read |
| `metrics-stream` | Streaming resource metrics |
| `shell-attach` | Reusable interactive shell using `connectOrCreate` |
| `net-basic` | Basic networking |
| `net-dns` | DNS filtering |
| `net-policy` | Network policies |
| `net-ports` | Port publishing |
| `net-secrets` | Secret injection |
| `net-tls` | TLS interception |

The `snapshot-fork` example keeps its historical directory name; it demonstrates restoring a saved disk snapshot. Live forking uses the `fork` API.
