figma_execute
Execute custom JavaScript in Figma's plugin context to handle complex canvas operations not covered by other tools; requires Canvas Bridge and can modify your document.
Instructions
Execute arbitrary JavaScript in Figma's plugin context with full access to the figma API. Use for complex operations not covered by other tools. Requires Canvas Bridge plugin. CAUTION: Can modify your document.
COMPONENT INSTANCES: For instances (node.type === 'INSTANCE'), use figma_set_instance_properties — direct text editing FAILS SILENTLY. Check instance.componentProperties for available props (may have #nodeId suffixes).
RESULT ANALYSIS: Check resultAnalysis.warning for silent failures (empty arrays, null returns).
VALIDATION: After creating/modifying visuals: screenshot with figma_capture_screenshot, check alignment/spacing/proportions, iterate up to 3x.
PLACEMENT: Always create components inside a Section or Frame, never on blank canvas. Use parent.insertChild(0, bg) for z-ordering backgrounds behind content.
HOUSEKEEPING (MANDATORY): Before creating: screenshot the target page to see existing content and find clear space. When creating: place inside a named Section, positioned BELOW or AWAY from existing content. Never overlap. After creating: screenshot to verify clean placement and no overlaps. On failure/retry: DELETE any partial artifacts (empty frames, orphaned layers, blank pages) before retrying. Use node.remove() to clean up. Pages: NEVER create a new page if one with that name already exists — use the existing one. If you created a blank page during a failed attempt, delete it. Layers: If your code creates helper frames, placeholder nodes, or intermediate layers that aren't part of the final result, remove them.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "figma_execute"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript code to execute. Has access to the 'figma' global object. Example: 'const rect = figma.createRectangle(); rect.resize(100, 100); return { id: rect.id };' | |
| timeout | No | Execution timeout in milliseconds (default: 5000, max: 30000) |