# Package and WebAssembly plugins

> Static plugins with templates, blocks and settings (no server-side code), and plugins with Go code compiled to WebAssembly or run as a separate service

Source: https://anasaki.live/docs/en/developers/package-wasm-plugins

Besides [JavaScript plugins](/docs/en/developers/js-plugins) there are two more kinds:

| Kind | Good for | Server-side code |
| --- | --- | --- |
| **Package (static)** | Designer blocks, banners, page scripts, webhooks | None — the fastest review |
| **Service (WASM / separate)** | Work that needs another language (e.g. Go) or its own container | WebAssembly in the CMS's sandbox, or a separate program |

## Package plugins

```text
hello-banner/
├── manifest.json
├── README.md
├── assets/banner.css      → <link rel=&#34;stylesheet&#34;> on every page
├── assets/banner.js       → <script defer> on every page
└── templates/
    ├── body.html          → inserted before </body>
    ├── card.html          → the block's template
    └── card.css           → the block's CSS (scoped automatically)
```

```json
{
  &#34;id&#34;: &#34;hello-banner&#34;,
  &#34;name&#34;: &#34;Hello Banner&#34;,
  &#34;version&#34;: &#34;1.0.0&#34;,
  &#34;icon&#34;: &#34;📣&#34;,
  &#34;category&#34;: &#34;marketing&#34;,
  &#34;minCore&#34;: &#34;2.0.0&#34;,
  &#34;permissions&#34;: [&#34;head&#34;, &#34;bodyEnd&#34;, &#34;blocks&#34;, &#34;settings&#34;],
  &#34;settings&#34;: [
    { &#34;key&#34;: &#34;text&#34;, &#34;type&#34;: &#34;text&#34;, &#34;label&#34;: { &#34;th&#34;: &#34;ข้อความ&#34;, &#34;en&#34;: &#34;Text&#34; }, &#34;default&#34;: &#34;Hello&#34; },
    { &#34;key&#34;: &#34;background&#34;, &#34;type&#34;: &#34;color&#34;, &#34;label&#34;: { &#34;th&#34;: &#34;สีพื้นหลัง&#34;, &#34;en&#34;: &#34;Background&#34; }, &#34;default&#34;: &#34;#4f46e5&#34; }
  ],
  &#34;head&#34;: [&#34;assets/banner.css&#34;, &#34;assets/banner.js&#34;],
  &#34;bodyEnd&#34;: &#34;templates/body.html&#34;,
  &#34;blocks&#34;: [{
    &#34;type&#34;: &#34;card&#34;,
    &#34;name&#34;: { &#34;th&#34;: &#34;การ์ด&#34;, &#34;en&#34;: &#34;Card&#34; },
    &#34;icon&#34;: &#34;🧩&#34;,
    &#34;template&#34;: &#34;templates/card.html&#34;,
    &#34;css&#34;: &#34;templates/card.css&#34;,
    &#34;props&#34;: [{ &#34;key&#34;: &#34;title&#34;, &#34;type&#34;: &#34;text&#34;, &#34;label&#34;: &#34;Title&#34;, &#34;default&#34;: &#34;Hi&#34; }]
  }]
}
```

```html
<!-- templates/body.html — every value is HTML-escaped automatically -->
<div class=&#34;hb&#34; style=&#34;--hb-bg: {{settings.background}}&#34;>{{settings.text}}</div>
```

- Placeholders: `{{settings.key}}`, `{{props.key}}` (blocks), `{{site.title}}`, `{{post.title}}`, `{{item.key}}` (inside a collection) — no loops or conditions
- **Never** put placeholders inside `` or `` — pass data to JS through `data-*` instead
- Setting types: `text`, `textarea`, `number`, `color`, `boolean`, `select`, `url`, `image`
- Block CSS is scoped under `.pb--` (use `:scope` or `&` for the wrapper)
- Webhooks: `&#34;webhooks&#34;: [{ &#34;event&#34;: &#34;post.published&#34;, &#34;url&#34;: &#34;{{settings.webhookUrl}}&#34; }]` — system events `post.published`, `user.created`, `media.uploaded`, or other plugins' events such as `form.submitted`

## WebAssembly plugins (a service inside the CMS)

Put `plugin.wasm` in the package with a `service` section — one-click install. The CMS runs it in a sandbox (no files, network or database beyond the APIs it asks for) with 256 MB of memory.

```json
{
  &#34;id&#34;: &#34;hello-service&#34;, &#34;name&#34;: &#34;Hello Service&#34;, &#34;version&#34;: &#34;1.0.0&#34;, &#34;icon&#34;: &#34;🛰&#34;,
  &#34;permissions&#34;: [&#34;service&#34;, &#34;blocks&#34;],
  &#34;service&#34;: {
    &#34;runtime&#34;: &#34;wasm&#34;,
    &#34;module&#34;: &#34;plugin.wasm&#34;,
    &#34;public&#34;: [&#34;/hello&#34;],
    &#34;api&#34;: [&#34;site&#34;, &#34;content&#34;, &#34;storage&#34;]
  }
}
```

Write it with the Go SDK (`sdk/go/anasaki` in the repository) and compile to `wasip1`:

```go
p := anasaki.New(anasaki.Config{Name: &#34;Hello Service&#34;, Version: &#34;1.0.0&#34;})
p.Public(&#34;GET /hello&#34;, func(w http.ResponseWriter, r *http.Request) {
    anasaki.Page(w, http.StatusOK, &#34;Hello&#34;, &#34;<h1>Hello!</h1>&#34;)   // shown inside the site's header/footer
})
p.Block(&#34;greeting&#34;, func(in anasaki.BlockInput) anasaki.BlockOutput { return anasaki.BlockOutput{HTML: &#34;…&#34;} })
log.Fatal(anasaki.Run(p, &#34;:9300&#34;))
```

```sh
GOOS=wasip1 GOARCH=wasm go build -trimpath -ldflags=&#34;-s -w&#34; -o package/plugin.wasm .
```

- API permissions: `site`, `mail`, `content`, `users`, `events`, `storage` (the plugin's key/value store), `http` (only `service.hosts`)
- Time: blocks and collections 3 seconds, public pages 30 seconds, admin pages 60 seconds — the module starts fresh for every request, so keep state in storage, not in global variables
- Declare `service.functions` so JavaScript code can call it with `plugins.call('', '', input)`

## A separate service (its own container)

The same code builds as a normal program (`go build`) and runs next to the CMS in `docker-compose.yml`:

```yaml
  hello-service:
    image: example/hello-service:1.0.0
    environment:
      ANASAKI_PLUGIN_ID: hello-service
      ANASAKI_PLUGIN_SECRET: ${HELLO_SERVICE_SECRET}
      ANASAKI_URL: http://studio:8090
    restart: unless-stopped
```

The site owner enters the service's address and passes the secret on the plugin's settings page ([Installing plugins](/docs/en/store/install-plugins)). The CMS signs every request with HMAC-SHA256 (the SDK checks it), and the service needs no public port.

> [!NOTE]
> The full specification (package limits, protocol, v1/v2 signatures, `pl__*` cookies) is in `docs/plugins.md` of the repository. Complete examples: `examples/plugins/` and `examples/service-plugins/hello-service`.
