Sixty-four bytes is a security model: what Telegram's widgets teach about agent-generated UI

Part of: Agent Security

Telegram's bot widgets have no network and one 64-byte request back to the bot. That is the right shape for agent-generated UI. Here is a checklist.

Telegram’s new bot widgets run in a sandbox with no network at all. The one way for data to leave is a request of at most 64 bytes to the bot that sent the widget, and only the bot can change what the widget shows. That is the right shape for any interface an agent generates: fixed code, state owned by the backend, and one narrow return channel. The number is small enough to reason about, which is what makes it a security model and not a hope.

Defensive security research. This post analyses publicly disclosed findings so the controls that stop them can be tested. It describes mechanisms, not procedures, and links the primary sources for anyone verifying the work.

What is a Telegram widget, exactly?

On November 9, 2026, Telegram shipped Bot API 10.4 with widgets. Its widgets guide describes a widget as one self-contained HTML document with inline CSS and JavaScript, at most 32,768 bytes of HTML and 4,096 bytes after the server compresses it, drawn inside a chat message. The changelog dates the release and adds a caveat: in production, widgets can currently be sent only to private chats with the bot. Groups, inline mode, and forwarding work on the test server.

The mental model is “fixed code plus changeable state.” The HTML is set when the widget is sent and cannot be replaced. What changes is the state, and per the guide only the bot writes it. The widget reads its state and redraws. It cannot set state itself. It can only ask.

Why is “no network” the whole point?

Because most of the ways a generated interface goes wrong need a network. Exfiltrating data needs somewhere to send it. Pulling in a second-stage script needs somewhere to fetch it from. Loading a tracking pixel needs an image URL.

Telegram’s documentation closes these off on the client. Network APIs throw NetworkDisabledError. External scripts, stylesheets, fonts and images never load, and images work only as data: URLs or inline SVG. The JavaScript runs in QuickJS, a small engine, not in a browser view. The client checks every change the widget makes to its page against a list of allowed features and draws only what passes. There are hard ceilings too: 8 MB of memory, 2,000 nodes, a CPU quota per second, and a widget that goes past them is stopped with its last frame left on screen.

An embedded engineer will recognize the pattern. You do not rely on the code being well behaved. You give it a small, fixed environment and make misbehavior impossible or cheap.

What can actually get out?

This is where I want to be careful, because “one narrow channel” is not “zero channels.”

  • The request. TelegramWidget.request() sends 1 to 64 bytes, on a tap, one at a time. In the private chat, a visible widget may also ask in the background, at most one every 5 seconds. Across all of it, requests are capped at 5 per 5 seconds per user and bot.
  • The answer. The bot replies within 15 seconds with up to 1,024 bytes. Only the widget that asked sees it. An answer cannot change state, trigger a notification, or open a URL.
  • Links. A widget can ask to open an https: link of up to 256 characters, but only on a real tap, and the user confirms with the full URL shown first.
  • State in. Each of the two state values is a text of up to 1,024 bytes that only the bot writes.

Do the arithmetic on the leak. At the documented rate, 64 bytes a second is about 3.8 KB a minute at the ceiling. That is not nothing, and a hostile widget could spend it on whatever it can see. But look at what it can see: its own state, the theme and language, and the viewer’s identity, and only where requests are allowed. A widget has no access to anything else, so there is not much to send. The design limits the pipe and the contents together.

The guide is honest about this too. Its privacy section says the bot learns whatever the widget’s code puts into those 64 bytes, such as language, theme, text size, bubble width, and time zone. So the claim is bounded, attributable, and received by code you own. It is not “nothing leaves.”

Who is on the other end of the channel?

You are. This is the part that generalizes. Telegram delivers a request with the user’s identity attached by Telegram itself, so from cannot be forged by the widget, and the request carries no information about where a forward ended up. The documentation tells bot authors to treat data as untrusted input, like a callback payload, keep the authoritative state on their side, and check each request against it. For paid or one-per-user actions, key them on the widget and user pair.

I wrote about the same reflex when an agent’s outbound path is the weak point, in your agent egress proxy never saw the DNS query. A narrow channel only helps if you control and inspect the far end. The widget sandbox shrinks the problem. Your bot’s request handler is where the remaining risk lives.

What would a generated-UI checklist look like?

Treat Telegram’s design as a template and fill in your own numbers. If an agent builds the interface your users see, every row below is a decision you should have written down.

PropertyWhat Telegram doesWhat to decide for your agent UI
Code is fixed once sentNo method replaces a sent widget’s HTMLVersion and sign the generated UI. Never mutate it in place.
State lives on the backendOnly the bot writes state, 1,024 bytes eachThe UI reads state and cannot write it. Writes go through your service.
No network from the UINetwork APIs throwBlock outbound at the sandbox, not in the app code.
One return channelrequest(), 64 bytes, on a tapPick a size cap. Smaller than you think you need.
Rate cap5 per 5 seconds per user and botPick a rate and enforce it where the request lands.
Identity on every callfrom set by TelegramThe caller’s identity comes from the platform, never from the payload.
Size budget on the code4,096 bytes compressedCap the generated UI’s size and complexity so it can be reviewed.
Treat the UI as publicDocs: never put secrets in a widgetAssume anything in the UI’s code or state can be read by the viewer.
Time limit on answers15 secondsFail closed on a timeout.

The identity row connects to whose bot is this: a signed caller identity beats anything the payload says about itself. The sandbox rows are the same layering as in the agent containment stack, where each layer assumes the others failed.

What does this design not solve?

Three things, and I would say so up front.

First, the bot. If the handler for those 64 bytes does something powerful on trust, a tiny message can still do large damage. A short string can be a command. Narrow input does not excuse sloppy validation.

Second, the contents of the state and the answers. A bot can still put sensitive data in its own state, and the widget will display it to whoever is looking, forwards included in the places forwards work.

Third, the content itself. A widget can draw a convincing fake button. The sandbox protects the device and the data path. It does not protect people from being misled by what is on screen.

How would I test any sandbox for generated UI?

Here are the probes I would run against any environment that hosts agent-written interfaces. The expected results below come from Telegram’s documentation. I have not run them on a live bot, so check them against your own build.

  1. Call fetch, open a WebSocket, set an image src to an external URL. Expect network errors, and no request visible at your egress point.
  2. Send a 65-byte request. Expect a type error before anything is sent.
  3. Call request() outside a tap. Expect NOT_ALLOWED where background requests are off.
  4. Push requests faster than the cap, with each one answered quickly. The documented cap is 5 per 5 seconds per user and bot. Expect RATE_LIMITED, and expect BUSY instead if an earlier request is still waiting.
  5. Let the bot sit on a request for 16 seconds. Expect TIMEOUT in the widget, and a refused late answer at the bot.
  6. Try to write state from the widget. Expect that there is no way to.
  7. Spin a loop past the CPU quota. Expect the widget to be stopped, with the last frame left behind.

Every probe has a number attached. That is what makes it a security model you can test, rather than an assurance you have to believe.

Sources

Frequently asked questions

What are Telegram bot widgets?

Telegram’s Bot API 10.4, dated November 9, 2026, lets bots send widgets: one self-contained HTML document with inline CSS and JavaScript, up to 32 KB of HTML and 4 KB after compression, drawn inside a chat message and run in a sandbox. The code is fixed when the widget is sent. Only the bot changes the widget’s state.

Can a Telegram widget make network requests?

No. Telegram’s documentation says fetch, XMLHttpRequest, WebSocket and every other network API throw NetworkDisabledError, and external scripts, stylesheets, fonts and images are never loaded. The widget runs in a small JavaScript engine, QuickJS, not in a WebView.

How does a widget talk to its bot?

Through a request of 1 to 64 bytes, sent on a tap, which arrives at the bot as an update. The bot answers within 15 seconds with up to 1,024 bytes that only the widget that asked receives. Requests are limited to 5 per 5 seconds per user and bot. The answer cannot change state; only separate bot calls write state.

Is a 64-byte limit enough to stop data leaving a widget?

It bounds it, it does not stop it. At the documented rate limit a widget could send roughly 64 bytes a second, and it can only send what it can see: its own state, the theme, and the viewer’s identity where requests are allowed. The security comes from the channel being narrow, rate limited, authenticated and received by code you own, and from the bot validating every request.

What should agent-generated UI copy from this design?

Fixed code once sent, state owned by the backend, no network from the UI, one small return channel with a size cap and a rate cap, an identity on every call that the client cannot forge, and a backend that treats every request as untrusted input.

Disagree or have a war story? Reply on X