SecurityPolicy is passed to Sandbox.create() via the security option. It composes PII detection, injection defense, network policy, transformation rules, audit logging, and environment variable security.
createSecurityPolicy()
Factory function for building a SecurityPolicy with defaults.
Injection defense. Pass
true for defaults, or an InjectionDefenseConfig
for custom settings.Regex transformation rules.
Network allowlist/denylist. See NetworkPolicy.
Audit logging. Pass
true for defaults.Environment variable masking config.
Toxicity detection on outbound HTTP bodies. See ToxicityConfig.
Code security scanner on outbound HTTP bodies. See CodeSecurityConfig.
Invisible-unicode detection on outbound HTTP bodies. See InvisibleTextConfig.
SecurityPolicy
SecurityPolicy interface
Helper functions
| Function | Description |
|---|---|
parseSecurityPolicy(data) | Deserialize a policy from raw JSON. |
securityPolicyToJSON(policy) | Serialize a policy to a JSON-friendly object. |
requiresTlsInterception(policy) | Returns true if PII, injection defense, or transforms are active. |
createPIIConfig()
Configure PII detection and redaction on outbound HTTP traffic.
Whether PII scanning is active.
PII types to scan for. Accepts
PIIType enum values or their string
equivalents.Action to take when PII is detected. One of
RedactionAction.Redact,
RedactionAction.Block, RedactionAction.LogOnly.When
true, replace redaction tokens in API responses with original values.PIIType enum
RedactionAction enum
PIIConfig interface
createInjectionDefenseConfig()
Configure prompt injection detection on outbound HTTP request bodies.
Whether injection defense is active.
Sensitivity level. One of
InjectionSensitivity.Low, Medium, High.
Higher sensitivity catches more patterns but may produce false positives.Action when injection is detected. One of
InjectionAction.Block,
InjectionAction.Sanitize, InjectionAction.LogOnly.Detection threshold (0.0–1.0). Sent to the API alongside
sensitivity so
the SDK wire format matches the Python SDK’s numeric-threshold form.Optional domain allowlist. When omitted, injection defense applies to all
outbound destinations.
InjectionSensitivity enum
InjectionAction enum
InjectionDefenseConfig interface
The TypeScript SDK uses
sensitivity (low/medium/high) for injection
thresholds. The Python SDK uses a numeric threshold (0.0–1.0). The API
accepts both representations.createNetworkPolicy()
Define which outbound connections the sandbox is allowed to make.
Destinations to allow. Accepts IP addresses, CIDR blocks, and domain names
with optional
*. wildcard prefix.Destinations to deny. Accepts IP addresses and CIDR blocks.
Whether all public traffic is allowed by default. Set to
false when
using allowOut as an allowlist.Replace the
Host header in all outbound requests with this value.ALL_TRAFFIC constant
NetworkPolicy interface
createTransformationRule()
Create a regex-based transformation rule with validation. The factory checks for ReDoS-vulnerable patterns (nested quantifiers) and validates the regex syntax before returning the rule.
Valid JavaScript regex pattern (max 1000 characters). Must not contain
nested quantifiers.
Replacement string. Supports regex back-references (e.g.
$1).Direction to apply the rule. One of
'outbound', 'inbound', 'both'.TransformDirection enum
TransformationRule interface
createAuditConfig()
Control what the MITM proxy logs for security events.
Whether audit logging is active.
Whether to include request bodies in audit log entries.
Whether to include response bodies in audit log entries.
How many hours to retain log entries.
AuditConfig interface
AuditEntry interface
createEnvSecurityConfig()
Control how environment variable values are masked in audit logs.
Glob patterns matched against uppercase variable names. Default:
['*_KEY', '*_SECRET', '*_TOKEN', '*_PASSWORD', '*_CREDENTIALS', 'API_KEY', 'SECRET_KEY'].Automatically redact matching variable values in audit logs.
EnvSecurityConfig interface
SecureEnvVar interface
createToxicityConfig()
Configure toxicity detection on outbound HTTP request bodies.
Whether toxicity detection is active.
Detection threshold in 0.0–1.0. Higher values fire only on more confident
detections.
Action when toxicity is detected.
Optional domain allowlist. When omitted, applies to all outbound destinations.
ToxicityConfig interface
createCodeSecurityConfig()
Configure the code-security scanner for outbound HTTP request bodies.
Whether code-security scanning is active.
Detection threshold in 0.0–1.0.
Languages to skip. When omitted, all detected languages are scanned.
Action when a security issue is detected.
Optional domain allowlist. When omitted, applies to all outbound destinations.
CodeSecurityConfig interface
createInvisibleTextConfig()
Detect and handle zero-width or otherwise invisible Unicode characters in
outbound HTTP bodies.
Whether invisible-text detection is active.
Action when invisible characters are detected.
Optional domain allowlist. When omitted, applies to all outbound destinations.