multi-tenant
Skill8 starsChanged 55 days agoMITView on GitHub
Use this skill when designing or reviewing secure multi-tenant AI agent platforms — tenant isolation for data, execution, memory, and billing. Triggers on multi-tenant, tenant isolation, RLS, SaaS, sandbox.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- zllovesuki/cloudflare-agent-skillstheir own version, first seen Apr 28, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- zllovesuki/cloudflare-agent-skills★ 9same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository6 other files it gives its agents.
- code-reviewSkill
- contributeSkill
- contributionSkill
- documentationSkill
- multi-agentsSkill
- project-architectureSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 10 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Do NOT trigger for single-user CLI tools, single-tenant prototypes with no shared infrastructure, or generic auth without a tenant boundary.
- Distinctive: line 37
If ambiguous, ask at most 2-3 questions (isolation model, enterprise dedicated-tenants?, compliance needs) — then propose and proceed.
- Very specific: line 44
Default to deny: authenticated → membership → ownership → role → policy → allow.
- Distinctive: line 56
Treat cache, vector recall, and event streams as leak vectors equal to the database.
- Very specific: line 66
Run the cross-tenant negative matrix in operations: A cannot read/update/delete B's agents, sessions, files, memory, cache, events, tools, …
- Very specific: line 72
Be explicit: Prefer explicit tenant_id ownership, explicit context propagation, and explicit authorization over implicit resolution or …
- Distinctive: line 74
Start simple, isolate strongly: Prefer shared tables + strict filtering + RLS for early SaaS.
- Distinctive: line 76
Prove it with negative tests: Every isolation claim needs a Tenant-A-vs-Tenant-B rejection test.
- Very specific: line 80
Do NOT trust client-provided tenant_id, bare resource IDs, or session IDs as authorization.
- Distinctive: line 81
Do NOT write unscoped queries, global cache keys, global memory namespaces, global credentials, or unscoped background jobs.
- Distinctive: line 82
Do NOT interpolate tenant values into SQL, shell, or paths — use parameterized queries and validated path joins inside the tenant root.
- Distinctive: line 83
Do NOT log, trace, or return secrets, and do NOT expose another tenant's telemetry, billing, or error details.
- Distinctive: line 84
Do NOT weaken isolation to simplify implementation, and do NOT ship without cross-tenant negative tests and a security-checklist pass.
- Distinctive: line 85
Do NOT embed secrets, real connection strings, or tenant PII in designs or examples.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Multi-Tenant
Shared infrastructure, strict tenant isolation — no accidental cross-tenant access.
Designs and reviews secure, production-grade multi-tenant systems for AI agent platforms where tenants share infrastructure but never share data, memory, files, credentials, or execution.
Purpose
Translate multi-tenant requirements into an end-to-end isolation design: trusted tenant context, enforced authorization, isolated data, sandboxed execution, namespaced stateful services, and per-tenant metering. Prevents the most common SaaS failure — filtering in one layer while leaking through cache, memory, jobs, logs, or sandboxes.
When to Use
- User asks to design, add, audit, or fix multi-tenancy in a SaaS / agent platform
- User mentions tenants, workspaces, organizations, isolation, data leakage, or cross-tenant access
- User needs tenant-aware auth, Row-Level Security, per-tenant sandboxes, memory, cache, queues, files, secrets, or billing
- User asks "how do we isolate tenants?", "is this tenant-safe?", "review for tenant leaks?"
- Keywords:
multi-tenant,tenant isolation,tenant_id,RLS,sandbox,SaaS,workspace isolation,cross-tenant
Do NOT trigger for single-user CLI tools, single-tenant prototypes with no shared infrastructure, or generic auth without a tenant boundary.
Workflow
[1. Model Context] ──> [2. Enforce Data] ──> [3. Isolate Execution] ──> [4. Namespace State] ──> [5. Meter & Observe] ──> [6. Verify & Ship]1. Model identity and establish TenantContext
- Map the ownership hierarchy:
Tenant → Users → Agents → Sessions → Runs → Tools / Files / Memory. - Define one canonical
TenantContext(tenantId,userId,role) resolved server-side from authentication + membership. Never trust a client-suppliedtenant_idalone. - List every tenant-owned resource (
agents,sessions,runs,messages,memories,files,credentials,usage,billing). Default: every resource gets explicittenant_id— see data-isolation. - If ambiguous, ask at most 2-3 questions (isolation model, enterprise dedicated-tenants?, compliance needs) — then propose and proceed.
2. Enforce authorization at the data boundary
- Apply the golden rule on every access:
RESOURCE_ID + TENANT_ID, never ID alone. PreferWHERE id = ? AND tenant_id = ?over load-then-check. - Choose a DB strategy deliberately — shared tables (default), separate schemas, or separate databases — per the decision table in data-isolation. Add RLS as a second line of defense for sensitive tables.
- Derive tenant from session in list APIs (
GET /agents, notGET /tenants/:id/agents/:idunless hierarchy is public). If a tenant ID appears in the URL, verify membership. - Default to deny:
authenticated → membership → ownership → role → policy → allow.
3. Isolate agent execution and integrations
- Give each execution its own sandbox (
Tenant → Agent → Sandbox → Container / MicroVM). Scope filesystem, CPU, memory, network, env vars, lifetime — see execution-isolation. - Inject only the secrets required for that run; prefer short-lived credentials. Never log, prompt, or trace secret values.
- Scope files (
tenant/{tenantId}/agent/{agentId}/...), git workspaces (one sandbox, one workspace, one tenant), MCP tools (tenant credentials, per-tool allowlist), and WebSocket subscriptions (verifysession belongs to current tenantbefore subscribing).
4. Namespace all stateful services
- Apply the pattern
tenant:{tenantId}:<resource>:<id>to cache keys, memory namespaces (memory/{tenant}/{agent}/...), vector filters (filter = { tenant_id }), queue payloads, and events — see stateful-services. - Propagate
tenantIdthrough every background job and retry; workers must re-validate ownership, never blindly trust the payload. - Treat cache, vector recall, and event streams as leak vectors equal to the database.
5. Meter, throttle, and observe per tenant
- Emit usage per
tenant → agent → run(tokens, tool calls, compute, storage). Enforce quotas (max_agents,max_concurrent_runs,max_tokens_per_day) before expensive work starts. - Rate-limit at
global → tenant → user → agent → sessionlevels so one tenant cannot starve others. - Tag every log, metric, and trace with
tenant_id; keep audit logs append-only for auth, membership, secret, and billing changes — see operations.
6. Verify isolation before shipping
- Run the cross-tenant negative matrix in operations: A cannot read/update/delete B's agents, sessions, files, memory, cache, events, tools, secrets, or billing — including indirect paths (
session → agent → file → run → memory). - Confirm failure paths preserve tenant context (retry, sandbox crash, permission revoked mid-run, tenant deleted mid-run).
- Close with the Definition of Done: independent execution + isolated data/memory/files/credentials/environments + separately measurable usage + enforceable quotas + rejected cross-tenant access + passing tests.
Instructions
- Be explicit. Prefer explicit
tenant_idownership, explicit context propagation, and explicit authorization over implicit resolution or global state. - Enforce at the boundary. Push checks to the data-access layer (
WHERE id + tenant_id), the cache-key builder, the job envelope, and the sandbox launcher — not scattered business logic. - Start simple, isolate strongly. Prefer shared tables + strict filtering + RLS for early SaaS; move to schemas or dedicated runtimes only on concrete enterprise, regulatory, or noisy-neighbor evidence.
- Keep control plane separate from agent runtime. Control plane owns tenant, user, agent, session, permissions, quotas, billing. Agent runtime owns reasoning, tools, execution. Do not scatter tenant checks inside the agent loop.
- Prove it with negative tests. Every isolation claim needs a Tenant-A-vs-Tenant-B rejection test; unverified isolation is a vulnerability.
Constraints
- Do NOT trust client-provided
tenant_id, bare resource IDs, or session IDs as authorization. - Do NOT write unscoped queries, global cache keys, global memory namespaces, global credentials, or unscoped background jobs.
- Do NOT interpolate tenant values into SQL, shell, or paths — use parameterized queries and validated path joins inside the tenant root.
- Do NOT log, trace, or return secrets, and do NOT expose another tenant's telemetry, billing, or error details.
- Do NOT weaken isolation to simplify implementation, and do NOT ship without cross-tenant negative tests and a security-checklist pass.
- Do NOT embed secrets, real connection strings, or tenant PII in designs or examples.
Examples
Example 1 — Add tenancy to an agent API
User: "Make
src/agents/multi-tenant."
Agent actions:
- Reads
src/agents/*,src/db/schema.*, auth middleware; lists tenant-owned tables missingtenant_id. - Introduces
TenantContext { tenantId, userId, role }in middleware; rewrites reads toWHERE id = $1 AND tenant_id = $2. - Namespaces cache (
tenant:{id}:agent:{id}), queues ({ tenantId, agentId, sessionId }), and vector filters. - Adds negative tests:
Tenant A token → GET /agents/<B-id> → 403/empty; verifies with test run.
Example 2 — Audit for tenant leaks
User: "Is
internal/memory/tenant-safe?"
Agent actions:
- Traces
similaritySearch(query)— flags missingfilter = { tenant_id }atinternal/memory/store.ts:42. - Checks cache keys (
agent:123→ leak; fix totenant:456:agent:123), logs (missingtenant_id), and job payloads. - Verdict:
Request changes— 1 blocking (unfiltered vector recall), 2 important (global cache key, unscoped retry job).
Example 3 — Isolate execution
User: "Agents run shell + git — isolate tenants."
Agent actions:
- Proposes
Tenant → Agent → Sandbox → Containerwith per-run workspacetenants/{tenantId}/agents/{agentId}/. - Scopes secrets per run, blocks
../traversal, separates git workspaces, allowlists MCP tools per tenant. - Adds lifecycle: provision → run → stream → persist → destroy; no abandoned sandboxes.
References
- references/data-isolation.md — Ownership model, DB strategies A/B/C, RLS, query patterns.
- references/execution-isolation.md — Sandboxes, secrets, files, git, MCP tools, WebSockets.
- references/stateful-services.md — Memory/vector, cache, queues, events.
- references/operations.md — Billing, rate limits, quotas, observability, audit, lifecycle, failures, testing matrix, security checklist, rollout order, Definition of Done.
- Companion skills:
project-architecture(module boundaries),code-review(diff audit),documentation(ADRs, runbooks). - Optional Jev gate (skipped without
JEV_API_KEY): send the isolation diff + negative-test results tojev_review. Full protocol: contribute Jev gates. Never send secrets or tenant PII.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

