figma_execute
Execute JavaScript within the Figma Plugin API sandbox to read design data or perform targeted modifications. Use for safe operations like retrieving node properties or updating specific attributes.
Instructions
Execute arbitrary JavaScript in the Figma Plugin API sandbox. Powerful and direct — use with care.
Prerequisites: Requires Figma bridge running and plugin connected. The code runs inside the Figma plugin context (not Node.js), so Node APIs (fs, path, etc.) are not available. Only the Figma Plugin API and standard browser globals are accessible.
Returns on success: The return value of the last expression in the code, JSON-serialized. Non-serializable values (functions, DOM nodes) are omitted.
Error behavior: Throws "Figma not connected" if no plugin is connected. Runtime errors in the plugin sandbox are caught and returned as { error: string, stack: string }.
IMPORTANT — this tool is powerful and can cause destructive mutations to the Figma file:
Safe read operations: node.getSharedPluginData(), figma.currentPage.selection, node.name, node.type, getting fills/effects
Safe targeted mutations: renaming nodes, updating a fill color, setting a variable binding on a single node
Do NOT use for full component creation — use create_spec + generate_code instead, which produces versioned, spec-traceable components
Do NOT replace entire frames or delete page-level frames with this tool
Do NOT call figma.closePlugin() — this terminates the bridge connection
Example safe reads:
figma.currentPage.selection.map(n => ({ id: n.id, name: n.name }))figma.getNodeById('123:456')?.namefigma.currentPage.children.map(n => n.name)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript to execute in the Figma Plugin API sandbox. Must be a valid JS expression or statement block. The return value (last expression result) is JSON-serialized and returned. Has access to the full Figma Plugin API (figma.*, PageNode, FrameNode, etc.) but not Node.js APIs. |