From bunny-edge
Scaffold, develop, and deploy Bunny CDN Edge Scripts with edge-replicated database. Use when working with Bunny edge scripting, edge functions, CDN middleware, HTMLRewriter, Bunny Database, or deploying scripts to Bunny's edge network.
How this skill is triggered — by the user, by Claude, or both
Slash command
/bunny-edge:bunny-edgeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
You are an expert in Bunny CDN Edge Scripting. Help the user scaffold, develop locally, and deploy edge scripts to Bunny's platform.
You are an expert in Bunny CDN Edge Scripting. Help the user scaffold, develop locally, and deploy edge scripts to Bunny's platform.
For full API details, runtime reference, and examples beyond what's covered here, see the supporting files in this skill directory:
Bunny Edge Scripts run on Deno + V8 at the CDN edge. There are two types:
BunnySDK.net.http.serve().BunnySDK.net.http.servePullZone(). Can be attached via Edge Rules.When the user asks to scaffold/create a new edge script project:
Create this file structure:
project-name/
script.ts
.github/
workflows/
deploy.yml
script.ts — starter template:
import * as BunnySDK from "@bunny.net/edgescript-sdk";
BunnySDK.net.http.serve(async (request: Request): Response | Promise<Response> => {
const url = new URL(request.url);
// Route handling
if (url.pathname === "/") {
return new Response("Hello from the edge!", {
headers: { "content-type": "text/plain" },
});
}
return new Response("Not Found", { status: 404 });
});
script.ts — starter template:
import * as BunnySDK from "@bunny.net/edgescript-sdk";
BunnySDK.net.http.servePullZone(
// In local dev, specify the origin URL. In production, the Pull Zone origin is used automatically.
{ url: "https://your-origin.example.com" },
)
.onOriginRequest(async (context) => {
// Modify request before it reaches origin
// Return a Request to modify, or a Response to short-circuit
return context.request;
})
.onOriginResponse(async (context) => {
// Modify response before it reaches the client and cache
return context.response;
});
.github/workflows/deploy.yml:
name: Deploy to Bunny Edge
on:
push:
branches:
- "main"
jobs:
publish:
runs-on: ubuntu-latest
name: "Deploy Edge Script"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Deploy Script to Bunny Edge Scripting
uses: BunnyWay/actions/deploy-script@main
with:
script_id: ${{ secrets.SCRIPT_ID }}
deploy_key: ${{ secrets.DEPLOY_KEY }}
file: "script.ts"
Scripts run locally with Deno:
deno run -A script.ts
This starts a local server. Test with curl or a browser. For middleware scripts, the url option in servePullZone() is used as the origin during local development.
IMPORTANT: GitHub repo creation constraint. You cannot link an existing GitHub repo to a Bunny edge script. The repo must be created from Bunny's side first:
script.ts)SCRIPT_ID and DEPLOY_KEY as GitHub repository secretsmain to trigger deploymentAlternatively, deploy via the Bunny API:
# Upload code
curl -X POST "https://api.bunny.net/compute/script/{id}/code" \
-H "AccessKey: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"Code": "..."}'
# Publish release
curl -X POST "https://api.bunny.net/compute/script/{id}/publish" \
-H "AccessKey: YOUR_API_KEY"
BunnySDK.net.http.serve(handler)serve(handler: (request: Request) => Response | Promise<Response>)
Receives standard Web API Request, must return Response.
BunnySDK.net.http.servePullZone(options)servePullZone(options: { url: string }): PullZoneHandler
Returns a chainable handler with:
.onOriginRequest(handler) — intercept before origin. Return Request to modify, Response to short-circuit..onOriginResponse(handler) — intercept before client/cache. Receives { request, response }, return modified Response.Streaming HTML transformation at the edge — no need to buffer the entire document:
new HTMLRewriter()
.on("a[href]", {
element(el) {
const href = el.getAttribute("href");
if (href?.startsWith("http://")) {
el.setAttribute("href", href.replace("http://", "https://"));
}
},
})
.transform(response);
See runtime-reference.md for full HTMLRewriter API.
const { response, socket } = request.upgradeWebSocket();
socket.addEventListener("message", (event) => {
socket.send(`Echo: ${event.data}`);
});
return response;
Requires enabling WebSockets on the Pull Zone: Pull Zone > General > WebSockets.
// Environment variable
const value = Deno.env.get("MY_VAR");
// or
import process from "node:process";
const value = process.env.MY_VAR;
Set via dashboard: Script > Env Configuration. Use Secrets for sensitive values (API keys, tokens) — they are encrypted and cannot be viewed after creation.
Fully managed libSQL (SQLite fork) database with global replication. Databases and edge scripts are deployed to the same regions for minimal latency.
Connect from Edge Scripts:
BUNNY_DATABASE_URL and BUNNY_DATABASE_AUTH_TOKEN as secretsimport { createClient } from "@libsql/client/web";
import process from "node:process";
const client = createClient({
url: process.env.BUNNY_DATABASE_URL,
authToken: process.env.BUNNY_DATABASE_AUTH_TOKEN,
});
// Parameterized query
const result = await client.execute({
sql: "SELECT * FROM users WHERE id = ?",
args: [1],
});
// Batch transaction (atomic, auto-rollback on failure)
await client.batch([
{ sql: "INSERT INTO users (name) VALUES (?)", args: ["Kit"] },
{ sql: "INSERT INTO users (name) VALUES (?)", args: ["Sam"] },
], "write");
Key details:
@libsql/client/web import path (not default) in edge scriptsSee database-reference.md for full SDK, SQL API, replication architecture, and transactions.
Sandboxed FS with 64MB storage. Writable paths: /home/user/ and /tmp/.
import * as fs from "node:fs/promises";
await fs.writeFile("/tmp/cache.json", JSON.stringify(data), "utf-8");
const content = await fs.readFile("/tmp/cache.json", "utf-8");
| Resource | Limit |
|---|---|
| CPU time per request | 30 seconds |
| Active memory | 128 MB |
| Subrequests per request | 50 |
| Script size | 10 MB |
| Startup time | 500 ms |
| Env variables per script | 128 |
| Env variable size | 2 KB |
| Virtual FS storage | 64 MB |
CPU time excludes I/O wait (fetch, etc.). Platform is forgiving for infrequent spikes.
HTMLRewriter for HTML transforms — it streams, avoiding buffering the full document.Content-Length and Content-Encoding headers when modifying the response body.npx claudepluginhub mheland/bunny-edge-plugin --plugin bunny-edgeProvides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.