Understand the Figma Plugin execution environment
Figma plugins run in a sandboxed environment divided into two parts: the main thread and the UI iframe. The main thread has direct access to the Figma document via the
figma global object. The optional UI runs in an iframe with access to standard browser APIs. Communication between the main thread and the UI is handled via asynchronous message passing using figma.ui.postMessage() and figma.ui.onmessage.