National Cyber Warfare Foundation (NCWF)login

arcjet-js for runtime security in AI apps and agents


0 user ratings
2026-10-25 05:32:07
milo
Red Team (CNA)
"arcjet-js

arcjet-js is a TypeScript SDK that embeds prompt injection detection, tool-call authorization, rate limiting, and PII redaction directly into AI application code for authorized defensive engineering teams.








Toolarcjet/arcjet-js — TypeScript monorepo of runtime security packages for AI apps, agents, and HTTP endpoints
CategoryRuntime application security SDK (AI/LLM security)
Primary UseEnforcing protect() and guard() checks for prompt injection detection, PII redaction, rate limiting, and tool-call authorization inside your own applications
Safe UseIntended for developers and authorized security teams hardening their own production apps, AI agents, and MCP servers; purely defensive, in-process pre-action enforcement
Telemetry NoteEmits logs and debug facets such as client_ip_provenance, DRY_RUN mode logs, and per-client warnings when forwarding headers like X-Forwarded-For are unverified — defenders can audit decisions via Arcjet's audit trail

arcjet-js is the open source JavaScript monorepo behind Arcjet, a runtime security platform that ships inside your application code rather than sitting in front of it as a network appliance. The core premise is straightforward and increasingly relevant: AI features and agents take real actions — calling tools, reading data, hitting APIs — and Arcjet places enforceable security checkpoints inside that code so each action is evaluated in real time, before it happens, with a full audit trail of what was decided. The repository currently sits at 683 stars, is written in TypeScript, and is licensed under Apache-2.0, which makes it genuinely embeddable in commercial products.


What makes the architecture interesting is the split between two entry points. Request protection — via @arcjet/next, @arcjet/node, @arcjet/bun, @arcjet/deno, @arcjet/fastify, @arcjet/nest, @arcjet/nuxt, @arcjet/remix, @arcjet/react-router, @arcjet/sveltekit, and @arcjet/astro — covers anything with an incoming Request object: HTTP route handlers, API endpoints, middleware. Guard protection, via @arcjet/guard, targets execution contexts that have no HTTP request at all: AI agent tool calls, MCP server handlers, queue workers, and background jobs. The README is explicit that you can run both in the same project, which reflects how modern applications actually split traffic-facing and background execution paths.


The feature matrix maps cleanly onto the two SDK families. Both request and guard variants support rate limiting (token bucket, fixed window, sliding window), prompt injection detection, and sensitive information detection covering PII, credit cards, and custom patterns. Request-only features include bot protection against scrapers, credential stuffers, and AI crawlers; the Shield WAF for SQL injection, XSS, and OWASP Top 10 patterns; email validation; signup form protection; expression-based request filters over IP, path, and headers; IP analysis covering geolocation, ASN, VPN, proxy, Tor, and hosting detection; and signup form protection. Guard-only, meanwhile, gains custom rules — your own local evaluation logic for tool-call authorization decisions.


For AI-specific workloads, the README's Vercel AI SDK example is the most instructive artifact. A single Next.js chat route composes shield({ mode: "LIVE" }), detectBot() with an empty allow list to block all automated clients that inflate inference costs, a tokenBucket() with a refillRate of 2,000 tokens per hour and capacity of 5,000 to enforce per-user budgets via characteristics: ["userId"], sensitiveInfo() to block PII types from ever reaching a prompt, and detectPromptInjection() to stop injection attacks before they reach the LLM. The pattern is defense-in-depth as code: each rule is declared, composable, and independently toggleable between LIVE and DRY_RUN modes.


The DRY_RUN versus LIVE distinction deserves attention from an operational standpoint. DRY_RUN logs decisions without blocking, which is the correct posture when tuning rules against production traffic — you can validate that bot detection or sensitive-info patterns match what you expect before flipping to enforcement. This is a mature design choice; naive security middleware that blocks on day one tends to get ripped out after the first false positive breaks a paying customer's workflow.


Guard mode is where arcjet-js differentiates itself from conventional WAF thinking. Tool-call authorization for agents and MCP servers is a problem the perimeter model cannot solve: by the time an agent invokes a tool, there is no HTTP request to inspect, only an internal function boundary. @arcjet/guard with detectPromptInjection() wrapped around an MCP tool handler, as the README suggests, puts the check at the point of action — the architectural location where an unauthorized tool call can actually be stopped. Custom rules extend this to arbitrary local evaluation logic, letting teams encode organizational policy directly into agent execution paths.


The getting-started flow is unusually agent-native. Beyond the standard npm i @arcjet/next or npm i @arcjet/guard installs, the README walks through authenticating with npx @arcjet/cli auth login, installing skills via npx @tanstack/intent@latest install, and letting a coding agent wire up protect() or guard() calls from prompts like adding bot protection and rate limiting to a chat route. The README is candid that intent hooks install editor hooks are convenience, not a security boundary, and recommends allowlisting skill sources in package.json under an intent.skills key — a rare instance of a vendor documenting the trust boundaries of its own onboarding tooling.


That candor extends to network positioning. The README carries a detailed warning about client IP resolution: when a platform-provided IP is unavailable, Arcjet may fall back to forwarding headers such as X-Forwarded-For, which clients can spoof if they can reach the application directly or if the proxy preserves client-supplied values. The mitigation is documented — make the app reachable only through a proxy that overwrites or safely appends forwarding headers, list every trusted hop in proxies, use helpers like cloudflare(), and inspect resolution via client.clientIpDetails(request) or findIpDetails() / resolveClientIp() from @arcjet/ip. Spoofed sources are marked unverified-header in the client_ip_provenance debug facet, and configurations trusting 0.0.0.0/0 or ::/0 emit warnings.


For defenders evaluating telemetry, this provenance model matters. Any security product whose rate limiting and bot detection key off client identity inherits the reliability of that identity, and Arcjet surfaces the uncertainty rather than hiding it — one warning per client instance, a debug facet to inspect, and rejection of malformed ipSrc values. In an authorized deployment review, checking that proxies is correctly scoped and that the app is not directly reachable is the first audit item; the second is confirming DRY_RUN rules aren't silently left in log-only mode where they imply protection that isn't being enforced.


The ecosystem support is broad and verifiable from the repository: example apps exist for Astro, Deno, Express, FastAPI, Fastify, NestJS, Next.js (with a live demo), Nuxt, React Router, Remix, SvelteKit, and Tanstack Start, plus blueprint recipes for AI quota control, malicious traffic, payment forms, VPN and proxy detection, traffic sampling, and custom rules. The npm version badge tracks the arcjet package, and the identical API across SDKs means moving between runtimes carries minimal relearning cost.


Where this fits in an authorized workflow is clear: arcjet-js is defensive infrastructure for teams building and hardening their own applications, not an assessment tool. Red teamers will find it interesting only as a control they may encounter on target; blue teams and product engineers will find it a composable way to enforce prompt injection defenses, PII exfiltration blocks, cost-abuse limits, and agent tool-call authorization in one declarative layer. For anyone operating AI features in production — especially MCP-based agents — the guard pattern alone makes the repository worth reading, and the transparent documentation of its own limitations is the strongest signal of engineering seriousness here.



Official project repository for arcjet/arcjet-js.

Download Tool

Educational analysis for authorized security professionals. Use only in controlled, authorized environments.






Source: OffensiveSec
Source Link: https://www.offsecblog.com/2026/10/arcjet-js-for-runtime-security-in-ai.html


Comments
new comment
Nobody has commented yet. Will you be the first?
 
Forum
Red Team (CNA)



Copyright 2012 through 2026 - National Cyber Warfare Foundation - All rights reserved worldwide.