Arcjet is the runtime security platform that ships with your AI code. Stop bots and automated attacks from burning your AI budget, leaking data, or misusing tools with Arcjet's AI security building blocks. Every feature works with any Bun application.
This is the Arcjet SDK for Bunrequest protection —
use it to protect HTTP route handlers and API endpoints. If you need to protect
AI agent tool calls, MCP server handlers, or background jobs (anything without
an HTTP request), see @arcjet/guard.
Getting started
Quick setup with an AI agent
Log in with the CLI:
npx @arcjet/cli auth login
Install the request protection skill to give your coding agent the docs it needs:
Detect and block prompt injection attacks — attempts to override your AI
model's instructions — before they reach your model. Pass the user's message
via detectPromptInjectionMessage on each protect() call.
import arcjet, { detectPromptInjection } from"@arcjet/bun";
import { env } from"bun";
const aj = arcjet({
key: env.ARCJET_KEY!,
rules: [
detectPromptInjection({
mode: "LIVE", // Blocks requests. Use "DRY_RUN" to log only
}),
],
});
exportdefault {
fetch: aj.handler(async (req) => {
const { message } = await req.json();
const decision = await aj.protect(req, {
detectPromptInjectionMessage: message,
});
if (decision.isDenied() && decision.reason.isPromptInjection()) {
returnnewResponse(
"Prompt injection detected — please rephrase your message",
{ status: 400 },
);
}
// Forward to your AI model...returnnewResponse("OK");
}),
};
Bot protection
Arcjet allows you to configure a list of bots to allow or deny. Specifying
allow means all other bots are denied. An empty allow list blocks all bots.
Available categories: CATEGORY:ACADEMIC, CATEGORY:ADVERTISING,
CATEGORY:AI, CATEGORY:AMAZON, CATEGORY:APPLE, CATEGORY:ARCHIVE,
CATEGORY:BOTNET, CATEGORY:FEEDFETCHER, CATEGORY:GOOGLE,
CATEGORY:META, CATEGORY:MICROSOFT, CATEGORY:MONITOR,
CATEGORY:OPTIMIZER, CATEGORY:PREVIEW, CATEGORY:PROGRAMMATIC,
CATEGORY:SEARCH_ENGINE, CATEGORY:SLACK, CATEGORY:SOCIAL,
CATEGORY:TOOL, CATEGORY:UNKNOWN, CATEGORY:VERCEL,
CATEGORY:WEBHOOK, CATEGORY:YAHOO. You can also allow or deny
specific bots by name.
import arcjet, { detectBot } from"@arcjet/bun";
import { isSpoofedBot } from"@arcjet/inspect";
import { env } from"bun";
const aj = arcjet({
key: env.ARCJET_KEY!,
rules: [
detectBot({
mode: "LIVE",
allow: [
"CATEGORY:SEARCH_ENGINE",
// See the full list at https://arcjet.com/bot-list
],
}),
],
});
exportdefault {
fetch: aj.handler(async (req) => {
const decision = await aj.protect(req);
if (decision.isDenied() && decision.reason.isBot()) {
returnnewResponse("No bots allowed", { status: 403 });
}
// Verifies the authenticity of common bots using IP data.if (decision.results.some(isSpoofedBot)) {
returnnewResponse("Forbidden", { status: 403 });
}
returnnewResponse("Hello world");
}),
};
Bot categories
Bots can be configured by category and/or by specific
bot name. For example, to allow search engines and the OpenAI
crawler, but deny all other bots:
Bots claiming to be well-known crawlers (e.g. Googlebot) are verified by
checking their IP address against known IP ranges. If a bot fails verification,
it is labeled as spoofed. Use isSpoofedBot from @arcjet/inspect to check:
Arcjet supports token bucket, fixed window, and sliding window algorithms.
Token buckets are ideal for controlling AI token budgets — set capacity to
the max tokens a user can spend, refillRate to how many tokens are restored
per interval, and deduct tokens per request via requested in protect().
The interval accepts strings ("1s", "1m", "1h", "1d") or seconds as
a number. Use characteristics to track limits per user instead of per IP.
import arcjet, { tokenBucket } from"@arcjet/bun";
import { env } from"bun";
const aj = arcjet({
key: env.ARCJET_KEY!,
characteristics: ["userId"], // Track per userrules: [
tokenBucket({
mode: "LIVE",
refillRate: 2_000, // Refill 2,000 tokens per hourinterval: "1h",
capacity: 5_000, // Maximum 5,000 tokens in the bucket
}),
],
});
const decision = await aj.protect(req, {
userId: "user-123",
requested: estimate, // Number of tokens to deduct
});
if (decision.isDenied() && decision.reason.isRateLimit()) {
returnnewResponse("Rate limit exceeded", { status: 429 });
}
Sensitive information detection
Detect and block PII in request content. Pass the content to scan via
sensitiveInfoValue on each protect() call. Built-in entity types:
CREDIT_CARD_NUMBER, EMAIL, PHONE_NUMBER, IP_ADDRESS. You can also
provide a custom detect callback for additional patterns.
import arcjet, { sensitiveInfo } from"@arcjet/bun";
import { env } from"bun";
const aj = arcjet({
key: env.ARCJET_KEY!,
rules: [
sensitiveInfo({
mode: "LIVE", // Blocks requests. Use "DRY_RUN" to log onlydeny: ["CREDIT_CARD_NUMBER", "EMAIL", "PHONE_NUMBER"],
}),
],
});
const decision = await aj.protect(req, {
sensitiveInfoValue: userMessage, // The text content to scan
});
if (decision.isDenied() && decision.reason.isSensitiveInfo()) {
returnnewResponse("Sensitive information detected", { status: 400 });
}
Shield WAF
Protect your application against common web attacks, including the OWASP
Top 10.
import arcjet, { shield } from"@arcjet/bun";
import { env } from"bun";
const aj = arcjet({
key: env.ARCJET_KEY!,
rules: [
shield({
mode: "LIVE", // Blocks requests. Use "DRY_RUN" to log only
}),
],
});
Create a single client instance and reuse it with withRule() for
route-specific rules. The SDK caches decisions and configuration, so creating a
new instance per request wastes that work.
Arcjet runtime security SDK for Bun — bot protection, rate limiting, prompt injection detection, PII blocking, and WAF
The npm package @arcjet/bun receives a total of 457 weekly downloads. As such, @arcjet/bun popularity was classified as not popular.
We found that @arcjet/bun demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.
Package last updated on 09 Jun 2026
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
More than 140 Mastra npm packages were compromised in a supply chain attack that used a typosquatted dependency to deliver a cross-platform infostealer during installation.