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.
| Property | What Telegram does | What to decide for your agent UI |
|---|---|---|
| Code is fixed once sent | No method replaces a sent widget’s HTML | Version and sign the generated UI. Never mutate it in place. |
| State lives on the backend | Only the bot writes state, 1,024 bytes each | The UI reads state and cannot write it. Writes go through your service. |
| No network from the UI | Network APIs throw | Block outbound at the sandbox, not in the app code. |
| One return channel | request(), 64 bytes, on a tap | Pick a size cap. Smaller than you think you need. |
| Rate cap | 5 per 5 seconds per user and bot | Pick a rate and enforce it where the request lands. |
| Identity on every call | from set by Telegram | The caller’s identity comes from the platform, never from the payload. |
| Size budget on the code | 4,096 bytes compressed | Cap the generated UI’s size and complexity so it can be reviewed. |
| Treat the UI as public | Docs: never put secrets in a widget | Assume anything in the UI’s code or state can be read by the viewer. |
| Time limit on answers | 15 seconds | Fail 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.
- Call
fetch, open aWebSocket, set an imagesrcto an external URL. Expect network errors, and no request visible at your egress point. - Send a 65-byte request. Expect a type error before anything is sent.
- Call
request()outside a tap. ExpectNOT_ALLOWEDwhere background requests are off. - 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 expectBUSYinstead if an earlier request is still waiting. - Let the bot sit on a request for 16 seconds. Expect
TIMEOUTin the widget, and a refused late answer at the bot. - Try to write state from the widget. Expect that there is no way to.
- 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
- Telegram Widgets, Telegram, checked Nov 11, 2026
- Bot API changelog, Bot API 10.4 (Nov 9, 2026), Telegram, checked Nov 11, 2026