Preview sandbox & wallet bridge
How previews are isolated and how they still reach your wallet. This page is part of the Building apps chapter of the TokenOS documentation.
- Preview sandbox & wallet bridge Generated code is untrusted until you have reviewed it, so every preview runs in a locked-down iframe. At the same time a Web3 app is useless without a wallet — so the IDE relays wallet calls to the preview through a bridge that only works after you click Allow . What the sandbox enforces (SEC-003) Every preview route is served with a Content-Security-Policy sandbox allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox — note: no allow-same-origin , so the preview has an opaque origin with no cookies, storage or access to your TokenOS session.
- frame-ancestors is restricted to TokenOS origins; a preview cannot be embedded elsewhere.
- A strict Permissions-Policy blocks camera, microphone, geolocation, payment, USB, display capture and MIDI.
- The headers are applied by middleware to every path under the preview prefixes, so new preview routes inherit them.
- Published apps at /api/apps/{slug} are intentionally not sandboxed — they are your reviewed product.
How the wallet bridge works
- Every served preview HTML receives a small inline script providing memory-backed localStorage / sessionStorage and bridged window.solana , window.phantom.solana and window.ethereum providers. Outside the IDE the shim is a no-op and the app talks to the browser's real wallet extension.
- When the app calls connect() , signMessage , signTransaction or signAndSendTransaction (Solana) or ethereum.request (EVM), the shim posts a tokenos:wallet message to the parent IDE.
- The IDE shows a prompt: Allow for this project or Deny . Allow is disabled until the IDE wallet is connected. Requests queue until you answer. Permission is memory-only, per project and preview URL — it resets when you reload.
- Allowed requests are executed with the wallet you connected in the IDE and the result is posted back as tokenos:wallet:result . Wallet events are forwarded as tokenos:wallet:event .
The chip
The header chip above the preview shows the bridge state — off , pending , allowed , denied — and is clickable: pre-allow before the app asks, revoke an allowed project, or reset a denial.
Inside the generated app
hooks/useWallet.js wraps this for React and hands pages a plain address string. RPC reads go through /api/solana-rpc (an allow-listed proxy) so no API key is ever present in client code.
, <>Every served preview HTML receives a small inline script providing memory-backed <Code>localStorage</Code> / <Code>sessionStorage</Code> and bridged <Code>window.solana</Code>, <Code>window.phantom.solana</Code> and <Code>window.ethereum</Code> providers. Outside the IDE the shim is a no-op and the app talks to the browser
connect · disconnect · signMessage · signTransaction · signAllTransactions · signAndSendTransaction · request
ethereum.request (eth_requestAccounts, eth_chainId, eth_sendTransaction, personal_sign, wallet_switchEthereumChain, wallet_addEthereumChain …), enable, send, sendAsync
eth_sign · eth_signTransaction (raw signing is never relayed)
Never add allow-same-origin to a preview iframe.
Design Mode and bridge messages are accepted only from the preview iframes (origin and source checks).
Nothing is relayed before the builder clicks Allow; a denial is remembered for the session.
Protected runtime files (config.js, lib/web3.js, lib/walletBridge.js, hooks/useWallet.js) are never rewritten by the sanitizers.
Browse the full TokenOS documentation or jump to the API reference, credits & pricing or FAQ.
About TokenOS
TokenOS is the AI operating system for the autonomous Web3 economy. It combines an agentic IDE that turns a prompt into a deployed dApp, a marketplace of x402-paid AI agents, a peer-to-peer AI inference market where anyone can sell spare API quota or GPU time for USDC, MCP and A2A connectors for Claude, Cursor and ChatGPT, and the $TOS utility and governance token on Solana.
Builders pay with prepaid credits; sellers and agent creators are paid for work actually delivered; TokenOS indexes, verifies and settles. Nothing on this site is investment advice, and node payouts, agent payments and referral credits are fees for usage — not token distributions or returns.