All skills
openai avatar

/cloudflare-deploy

@bf9e226 official
by openaiopenai/skills28k stars
1,891

Deploy applications and infrastructure to Cloudflare using Workers, Pages, and related platform services. Use when the user asks to deploy, host, publish, or set up a project on Cloudflare.

Use this Skill: https://skilld.dev/gh/openai/skills/cloudflare-deploy

This session only. Nothing lands on disk.

referencesbindingsapi.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Bindings API Reference

TypeScript Types

Cloudflare generates binding types via npx wrangler types. This creates .wrangler/types/runtime.d.ts with your Env interface.

Generated Env Interface

After running wrangler types, TypeScript knows your bindings:

interface Env {
  // From wrangler.jsonc bindings
  MY_KV: KVNamespace;
  MY_BUCKET: R2Bucket;
  DB: D1Database;
  MY_SERVICE: Fetcher;
  AI: Ai;
  
  // From vars
  API_URL: string;
  
  // From secrets (set via wrangler secret put)
  API_KEY: string;
}

Binding Types

Config TypeScript Type Package
kv_namespaces KVNamespace @cloudflare/workers-types
r2_buckets R2Bucket @cloudflare/workers-types
d1_databases D1Database @cloudflare/workers-types
durable_objects.bindings DurableObjectNamespace @cloudflare/workers-types
vectorize VectorizeIndex @cloudflare/workers-types
queues.producers Queue @cloudflare/workers-types
services Fetcher @cloudflare/workers-types
ai Ai @cloudflare/workers-types
browser Fetcher @cloudflare/workers-types
analytics_engine_datasets AnalyticsEngineDataset @cloudflare/workers-types
hyperdrive Hyperdrive @cloudflare/workers-types
rate_limiting RateLimit @cloudflare/workers-types
workflows Workflow @cloudflare/workers-types
mtls_certificates / vars / text_blobs / data_blobs string Built-in
wasm_modules WebAssembly.Module Built-in

Accessing Bindings

Method 1: fetch() Handler (Recommended)

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const value = await env.MY_KV.get('key');
    return new Response(value);
  }
}

Why: Type-safe, aligns with Workers API, supports ctx for waitUntil/passThroughOnException.

Method 2: Hono Framework

import { Hono } from 'hono';

const app = new Hono<{ Bindings: Env }>();

app.get('/', async (c) => {
  const value = await c.env.MY_KV.get('key');
  return c.json({ value });
});

export default app;

Why: c.env auto-typed, ergonomic for routing-heavy apps.

Method 3: Module Workers (Legacy)

export async function handleRequest(request: Request, env: Env): Promise<Response> {
  const value = await env.MY_KV.get('key');
  return new Response(value);
}

addEventListener('fetch', (event) => {
  // env not directly available - requires workarounds
});

Avoid: Use fetch() handler instead (Method 1).

Type Generation Workflow

Initial Setup

# Install wrangler
npm install -D wrangler

# Generate types from wrangler.jsonc
npx wrangler types

After Changing Bindings

# Added/modified binding in wrangler.jsonc
npx wrangler types

# TypeScript now sees updated Env interface

Note: wrangler types outputs to .wrangler/types/runtime.d.ts. TypeScript picks this up automatically if @cloudflare/workers-types is in tsconfig.json "types" array.

Key Binding Methods

KV:

await env.MY_KV.get(key, { type: 'json' });  // text|json|arrayBuffer|stream
await env.MY_KV.put(key, value, { expirationTtl: 3600 });
await env.MY_KV.delete(key);
await env.MY_KV.list({ prefix: 'user:' });

R2:

await env.BUCKET.get(key);
await env.BUCKET.put(key, value);
await env.BUCKET.delete(key);
await env.BUCKET.list({ prefix: 'images/' });

D1:

await env.DB.prepare('SELECT * FROM users WHERE id = ?').bind(userId).first();
await env.DB.batch([stmt1, stmt2]);

Service:

await env.MY_SERVICE.fetch(new Request('https://fake/path'));

Workers AI:

await env.AI.run('@cf/meta/llama-3.1-8b-instruct', { prompt: 'Hello' });

Queues:

await env.MY_QUEUE.send({ userId: 123, action: 'process' });

Durable Objects:

const id = env.MY_DO.idFromName('user-123');
const stub = env.MY_DO.get(id);
await stub.fetch(new Request('https://fake/increment'));

Runtime vs Build-Time Types

Type Source When Generated Use Case
@cloudflare/workers-types npm install Base Workers APIs (Request, Response, etc.)
wrangler types After config change Your specific bindings (Env interface)

Install both:

npm install -D @cloudflare/workers-types
npx wrangler types

Type Safety Best Practices

  1. Never use any for env:
// ❌ BAD
async fetch(request: Request, env: any) { }

// ✅ GOOD
async fetch(request: Request, env: Env) { }
  1. Run wrangler types after config changes:
# After editing wrangler.jsonc
npx wrangler types
  1. Check generated types match config:
# View generated Env interface
cat .wrangler/types/runtime.d.ts

See Also

Source: SKILL.md on GitHub

2 warnings17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides comprehensive guidance for deploying and managing infrastructure on the Cloudflare platform. It includes extensive educational material on secure development practices, such as preventing SQL injection and managing secrets effectively. No malicious patterns or security risks were identified.

  • Socket17d

    2 alerts: gptAnomaly

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    310/310 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at bf9e226. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Activeupdated 8 months ago

README badge

README badge for openai/skills/cloudflare-deploy

Deploys applications and infrastructure to Cloudflare's platform, including Workers, Pages, D1, R2, Durable Objects, KV, and other services. Use decision trees to route to the right Cloudflare product based on compute, storage, AI, networking, security, or media needs.

Generated from the current SKILL.md.

Does this skill cover all Cloudflare products?
The skill is a consolidated index covering compute, storage, AI, networking, security, media, and developer tools on Cloudflare. It uses decision trees to route you to the right product reference, then loads detailed guidance for that product.
What authentication is required before deploying?
Run `npx wrangler whoami` to check if authenticated. For local deployment, use `wrangler login` (one-time OAuth). For CI/CD, set the `CLOUDFLARE_API_TOKEN` environment variable.
What should I do if deployment fails due to network issues?
Rerun the deploy with `sandbox_permissions=require_escalated` to grant elevated network access, which is required for outbound requests to Cloudflare during deployment.
How long does a Cloudflare deployment typically take?
Deployments may take several minutes. Use appropriate timeout values in your configuration or CI/CD environment.

Generated from the current SKILL.md. These answers refresh after source changes.