Skip to content
Back to skills

Sandbox Tokens

ASecurity

Count, encode, and decode LLM tokens in a Code node or CodeAct action, with js-tiktoken running on the host

  • 552 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 1, 2026
ai-agentsgonode

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned September 1, 2026

npx -y skills add nodetool-ai/nodetool --skill sandbox-tokens --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sandbox Tokens?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Sandbox Tokens
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nodetool-ai-sandbox-tokens/badge)](https://www.skillsdirectory.com/skills/nodetool-ai-sandbox-tokens)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: sandbox-tokens
description: Count, encode, and decode LLM tokens in a Code node or CodeAct action, with js-tiktoken running on the host
---

# Token counting in the sandbox

Specifier: `@nodetool-ai/sandbox-tokens`. Import it at the top of the body.

One encoding's BPE ranks are several megabytes, well past the 1 MB cap on a
compiled guest module, so this pack is a **host module**: the import resolves to
a generated facade over NodeTool's own implementation. The ranks load once per
process per encoding.

This is what the removed `nodetool.text.CountTokens` node did.

## count — how many tokens a text costs

```js
import { count } from "@nodetool-ai/sandbox-tokens";

const tokens = await count(inputs.text, "cl100k_base");
return { tokens, fitsContext: tokens < 8000 };
```

Encodings: `cl100k_base` (default — GPT-4, GPT-3.5), `o200k_base` (GPT-4o),
`p50k_base`, `r50k_base`. Empty text is 0 without loading anything.

## encode / decode — the token ids themselves

```js
import { encode, decode } from "@nodetool-ai/sandbox-tokens";

const ids = await encode(inputs.text);
// Truncate on a token boundary rather than a character one.
return { head: await decode(ids.slice(0, 500)) };
```

## Gotchas

- **All three are async.**
- **5 MB per call**, the shared host-module text cap.
- **tiktoken is OpenAI's tokenizer.** Anthropic, Gemini, and local models count
  differently — treat the number as an estimate for anything else.
- **Round-tripping is not free.** `decode(encode(t))` allocates the ranks and
  two passes; use `count` when you only need the number.

Files in this skill

  • SKILL.md1.6 KB
  • package.json856 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.