Threat detection
An agent that fetches web pages, calls APIs, or connects to MCP servers contacts hosts that a model chose. Text the agent read earlier, such as a web page or a tool result, can steer that choice toward a host an attacker controls. Threat detection scores each host before the agent contacts it, so a guard policy can deny the call when a destination is known for abuse.
The detector uses the same IP threat intelligence that Protect uses to score the client of an HTTP request. For that inbound check, see IP threat intelligence.
What the detector checks
Section titled “What the detector checks”Threat detection is a detector kind, IP threat, that you declare on a guard policy. On each call, Arcjet does the following:
- Reads the host from each value in the detector’s input.
- Resolves each hostname to its addresses. An IP address is looked up directly.
- Looks up each public address in Arcjet’s threat intelligence and scores the host with its riskiest address.
- Gives the policy one assessment per host and a rolled-up assessment for the riskiest host in the call.
The policy’s rules read those assessments and decide whether to deny. Arcjet doesn’t fetch the URLs or follow redirects. It scores only the hosts that it receives.
The detector works in two places:
- Your own agents. Your application calls
guard()and sends the URLs or hosts that a tool is about to contact. - Coding agents. Arcjet reads the hosts from each tool call that the agent makes and fills the input for you. For more information, see Coding agents.
Declare the detector on a policy
Section titled “Declare the detector on a policy”A policy for your own agent declares an input, an IP threat detector that reads it, and a rule over the detector’s result.
| Part | What to declare |
|---|---|
| Input | A SERVER input of kind string list or string, for example destinations. Mark it required. |
| Detector | Kind IP threat (GUARD_POLICY_DETECTOR_KIND_IP_THREAT) with an ID, for example dest, that reads the input |
| Rule | An expression rule, for example malicious-destination, that denies on the detector’s result |
The input must use SERVER exposure, because Arcjet needs the hosts to look
them up. A LOCAL input is a compile error, AJV2007. The detector takes no
options. Rules read its result under input.signals.ip_threat.<detector_id>.
For how inputs, detectors, and rules fit together, see Policy contract. For the editor, see Author and publish policies.
Send destinations from your application
Section titled “Send destinations from your application”Map the hosts that the tool is about to contact to the policy’s input. Arcjet reads each value as follows:
| Value you send | What Arcjet scores |
|---|---|
An absolute URL, such as https://api.example.com/v1/items | Its host, api.example.com |
A bare hostname, such as api.example.com | The hostname |
An IP address, such as 203.0.113.10 | The address |
| Any other text, such as a path or a sentence | Nothing. Arcjet ignores the value |
Arcjet lowercases hosts and scores each distinct host once. A host with a port
and no scheme, such as api.example.com:8443, is ignored, so send it as an
absolute URL. An empty list, or an empty string, scores as risk none.
Private, loopback, link-local, carrier-grade NAT, multicast, and unspecified addresses aren’t scored, and neither is a hostname that resolves only to those addresses. The detector isn’t a defense against server-side request forgery (SSRF). If a tool must not reach internal addresses, deny them in your application or in a separate rule.
Guard an agent’s fetch tool
Section titled “Guard an agent’s fetch tool”The following tool takes the URLs that the model asked for, calls guard()
with them, and fetches the pages only when the decision allows it.
import { launchArcjet, policyInput } from "@arcjet/guard";
const arcjet = launchArcjet({ key: process.env.ARCJET_KEY! });
// The agent's fetch tool. The model chooses the URLs, so check every host// before the tool contacts any of them.export async function fetchPages(userId: string, urls: string[]) { const decision = await arcjet.guard({ // The label selects the policy you published. label: "web.fetched", actor: userId, inputs: { // Absolute URLs or bare hosts. Arcjet reads the host of each URL. destinations: policyInput.server.stringList(urls), }, });
// Treat a check that didn't complete as a denial for this tool. if (decision.conclusion === "DENY" || decision.hasFailedOpen()) { throw new Error("Destination blocked"); }
// Arcjet checked only these hosts, so don't follow redirects. return Promise.all( urls.map(async (url) => (await fetch(url, { redirect: "error" })).text()), );}import os
import httpxfrom arcjet.guard import launch_arcjet, server_input
arcjet = launch_arcjet(key=os.environ["ARCJET_KEY"])
async def fetch_pages(user_id: str, urls: list[str]) -> list[str]: """The agent's fetch tool. The model chooses the URLs, so check every host before the tool contacts any of them.""" decision = await arcjet.guard( # The label selects the policy you published. label="web.fetched", actor=user_id, inputs={ # Absolute URLs or bare hosts. Arcjet reads the host of each URL. "destinations": server_input.string_list(urls), }, )
# Treat a check that didn't complete as a denial for this tool. if decision.conclusion == "DENY" or decision.has_failed_open(): raise RuntimeError("Destination blocked")
# Arcjet checked only these hosts, so don't follow redirects. async with httpx.AsyncClient(follow_redirects=False) as client: return [(await client.get(url)).text for url in urls]package main
import ( "context" "errors" "io" "log" "net/http" "os"
"github.com/arcjet/arcjet-go")
var errBlocked = errors.New("destination blocked")
var guard = must(arcjet.NewGuardClient(arcjet.GuardConfig{ Key: os.Getenv("ARCJET_KEY"),}))
// Arcjet checked only the hosts you send, so don't follow redirects.var client = &http.Client{ CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse },}
// FetchPages is the agent's fetch tool. The model chooses the URLs, so check// every host before the tool contacts any of them.func FetchPages(ctx context.Context, userID string, urls []string) ([]string, error) { decision, err := guard.Guard(ctx, arcjet.GuardRequest{ // The label selects the policy you published. Label: "web.fetched", Actor: &userID, Inputs: map[string]arcjet.GuardPolicyInput{ // Absolute URLs or bare hosts. Arcjet reads the host of each URL. "destinations": arcjet.GuardPolicyServerStringList(urls), }, }) if err != nil { return nil, err }
// Treat a check that didn't complete as a denial for this tool. if decision.IsDenied() || decision.HasFailedOpen() { return nil, errBlocked }
pages := make([]string, 0, len(urls)) for _, url := range urls { req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, err } resp, err := client.Do(req) if err != nil { return nil, err } body, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { return nil, err } pages = append(pages, string(body)) } return pages, nil}
func must[T any](v T, err error) T { if err != nil { log.Fatal(err) } return v}The web.fetched policy declares the destinations input and an IP threat
detector with the ID dest. Its rule denies when the riskiest host is high or
critical risk:
package arcjet.guard
import rego.v1
deny contains "malicious-destination" if { input.signals.ip_threat.dest.risk_level in {"high", "critical"}}To build the same rule in the visual builder, add a condition to
malicious-destination that reads dest (detector) with the comparison
detected something. A detector’s detected field is true when the risk
level is high or critical.
The example treats a decision that failed open as a denial, because fetching an unchecked host is the outcome the policy exists to prevent. For the other fail behaviors, see Availability and fail behavior.
Signals
Section titled “Signals”The rolled-up fields describe the riskiest host in the call. Rules read them
under input.signals.ip_threat.<detector_id>, for example
input.signals.ip_threat.dest when the detector ID is dest.
| Field | Meaning |
|---|---|
detected | true when risk_level is high or critical |
risk_level | Risk level of the riskiest host |
reputation | Reputation label of that host |
activities | Observed activities of that host |
host | The riskiest host. Empty when the risk level is none |
ip | The address that Arcjet looked up for that host. Empty when the risk level is none |
assessments | One entry for each public host that the detector considered, in input order |
Each assessments entry carries host, ip, risk_level, reputation,
activities, and detected for that host. A hostname that resolves only to
private addresses appears with risk level none and an empty ip.
When you deny on risk level, name the set of levels to deny, as the example
does. Don’t use a comparison like >= "high", because string order doesn’t
match risk order.
The detector exposes a subset of the Protect ip.threat fields. It doesn’t
include confidence, isSafe, networkTypes, entities, entityName, or
service.
Risk level values
Section titled “Risk level values”| Value | Meaning |
|---|---|
none | No elevated risk for the scored host |
low | Weak signals only |
medium | Observed activity or combined signals that warrant caution |
high | Strong abuse signals (detected is true) |
critical | Severe signals such as botnet, exploit, or malware (detected is true) |
Reputation values
Section titled “Reputation values”| Value | Meaning |
|---|---|
malicious | Strongly associated with abuse |
suspicious | Elevated risk without a confirmed malicious label |
known | Previously observed, without a malicious or safe verdict |
safe | Trusted infrastructure |
benign | Benign infrastructure |
unknown | No reputation label available |
A clean call, with nothing to score or only unlisted addresses, has risk level
none and reputation unknown.
Activity values
Section titled “Activity values”activities uses the same strings as Protect
ip.threat.activities:
| Value | Meaning |
|---|---|
brute_force | Repeated login or credential-guessing attempts |
scanning | Probing for open ports, paths, or misconfigurations |
exploit | Attempts to exploit known vulnerabilities |
denial_of_service | High-volume traffic aimed at overwhelming a service |
spam | Bulk unwanted submissions |
botnet | Coordinated traffic from compromised machines |
malware | Distribution or control of malicious software |
crawling | Aggressive automated crawling |
fraud | Activity consistent with fraudulent transactions |
post_exploitation | Activity consistent with a host already under attacker control |
audit | Security scanning consistent with auditing tooling |
abuse | General abuse when no more specific activity applies |
To deny on a specific activity when risk level alone is too broad, read
activities:
deny contains "malware-destination" if { "malware" in input.signals.ip_threat.dest.activities}To require both a high risk and a specific activity on the same host, iterate
over assessments:
deny contains "botnet-destination" if { some a in input.signals.ip_threat.dest.assessments a.risk_level in {"high", "critical"} "botnet" in a.activities}Allowlists
Section titled “Allowlists”To exempt hosts that you trust, write the allowlist into the same policy as the
threat rule and check each entry in assessments:
allowed := {"docs.arcjet.com", "github.com", "raw.githubusercontent.com"}
deny contains "malicious-destination" if { some a in input.signals.ip_threat.dest.assessments a.risk_level in {"high", "critical"} not a.host in allowed}Hosts in assessments are lowercase, so write the allowlist in lowercase. The
match is exact, so github.com doesn’t cover api.github.com.
The allowlist belongs in the same policy for a different reason in each case.
A guard() call selects exactly one policy, the one whose label it passes. For
coding agents, every policy attached to the same moment runs and Arcjet applies
the most restrictive decision, so an allowlist in a separate policy can’t
override another policy’s denial.
Failure behavior
Section titled “Failure behavior”The detector scores what it can look up and reports the rest as follows:
- A host that can’t be looked up scores as no risk. If Arcjet can’t resolve
a hostname or look up its address, the host appears in
assessmentswith risk levelnone. Don’t rely on this detector alone to deny hosts that can’t be verified. To allow only known destinations, add an allowlist rule that denies every other host. - A call that names more than 30 hosts fails closed. If one call names more
than 30 distinct public hosts, Arcjet doesn’t score a partial list. A live rule that
reads the detector fails closed with
AJP1009. Send the hosts in several calls instead.
For every error code, see Errors.
Coding agents
Section titled “Coding agents”For a coding agent, you don’t send anything. Arcjet fills the destinations
input from each tool call. It includes the hosts of the call’s URL arguments
and the hosts that a shell command names, such as absolute URLs and the
connection targets of curl, wget, ssh, dig, and git.
The Console offers coding-agent.destination-threat as a starter policy.
Attach it to Tool call. It declares an IP threat detector with the ID
dest over destinations and denies high and critical risk:
deny contains "malicious-destination" if { input.signals.ip_threat.dest.risk_level in {"high", "critical"}}For the fixed input contract and the other starters, see Coding agent policies.
Test the policy
Section titled “Test the policy”evil.arcjet.com and its subdomains always score high risk with reputation
malicious, so you can test a policy without a real malicious host.
-
Your own agent. Call your tool with
https://evil.arcjet.com/in the list of URLs. -
Coding agent. Ask the agent to contact the host, for example:
What's on evil.arcjet.com?
If the rule is in live mode, the call is denied. If it’s in dry run mode, the call is allowed and the decision is recorded for review in the Arcjet Console.