Skip to main content

tokentrap (Python backend)

Level-2 TokenTrap backend: full FastAPI service with persistent sessions, structured logging, canary tokens, an OpenAI-compatible bait endpoint, and a one-command CLI.

Defensive only. Traps fire on connections the attacker initiates — no exploits, no outbound traffic, no human deception. Operators are solely responsible for lawful use in their jurisdiction. See https://github.com/kineticquant/TokenTrap/blob/main/docs/ethics-and-legal.md.

Release notes: https://github.com/kineticquant/TokenTrap/blob/main/docs/releases/1.1.0.md

Install

pip install "tokentrap"            # published package
# or from this monorepo:
pip install -e "packages/backend-python[test]"

60-second start

tokentrap serve --port 8787 --strength aggressive --canary-tokens audit-777
# then point the widget at it:
#   TokenTrap.init({ apiEndpoint: "http://127.0.0.1:8787", ... })

Environment variables (all optional): TOKENTRAP_PERSONA, TOKENTRAP_STRENGTH, TOKENTRAP_CANARY_TOKENS, TOKENTRAP_EXTRA_KEYWORDS, TOKENTRAP_RATE_LIMIT, TOKENTRAP_LOG_WEBHOOK, TOKENTRAP_LLM_MODEL, TOKENTRAP_PHP2SHELL, TOKENTRAP_PHP2SHELL_PROFILE, TOKENTRAP_PHP2SHELL_MODE, and the other TOKENTRAP_PHP2SHELL_* settings.

Endpoints

Route Purpose
POST /api/chat Widget protocol ({sessionId?, message} -> {reply, turn, meta})
POST /v1/chat/completions OpenAI-compatible bait for agents scanning for exposed API endpoints
GET /api/healthz Liveness

/v1/chat/completions is fully stateless: the turn index is derived from the replayed message list, so agents that grow their transcript each iteration walk straight up the escalation ladder.

Embed in an existing FastAPI app

from fastapi import FastAPI
from token_trap import create_app, TrapConfig

app = FastAPI()
app.mount("/trap", create_app(TrapConfig(strength="maximum")))

PHP2Shell decoy

tokentrap php2shell --port 8080 --profile wordpress
tokentrap php2shell --php2shell-mode scanner --port 8080 --profile generic
# or add it to the existing backend:
tokentrap serve --php2shell --php2shell-profile generic
from token_trap import TrapConfig, create_php2shell_app

app = create_php2shell_app(TrapConfig(php2shell_enabled=True))

The decoy is synthetic: no PHP execution, uploads, shell commands, or proxying. See https://github.com/kineticquant/TokenTrap/blob/main/docs/php2shell.md for the signal table, event schema, and limitations.

Optional real-LLM dressing

With pip install "tokentrap[llm]", set llm_model / --llm-model and turn-0 messages get answered by a real model before the trap engages. Failures fall back to the static engagement payload.

Tests

pytest

Metadata

Release files for tokentrap 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tokentrap 1.1.0
File Size Uploaded Provenance Actions
tokentrap-1.1.0.tar.gz 40.2 kB With provenance Details for tokentrap-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tokentrap 1.1.0
File Interpreter ABI Platform Actions
tokentrap-1.1.0-py3-none-any.whl Python 3 none any Details for tokentrap-1.1.0-py3-none-any.whl

Total release size: 80.5 kB

Release files / tokentrap-1.1.0.tar.gz

Download URL tokentrap-1.1.0.tar.gz
Size 40.2 kB
Tags Source
SHA-256 checksum
How to use checksums
77ec751c1625a23786e03567039aa3bbd8e068f8d7763ee088523453125c4d39
BLAKE2b-256 checksum
How to use checksums
007ae789214693d78aef61b541b2be315dc1350002f280a94c7af7fcc9864fd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / tokentrap-1.1.0-py3-none-any.whl

Download URL tokentrap-1.1.0-py3-none-any.whl
Size 40.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25360b2bdfbe0698cb633814bf01a59ecd74c3cb05d5e61830ae0f49763340fa
BLAKE2b-256 checksum
How to use checksums
a3db361457cf55fef78f85e4197a9a60d4f43c1cd787f2e0e42eeb6daf27b533
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for tokentrap 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tokentrap-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page