Skip to content

Sandbox

New in v3.7.0. The Sandbox is where code your AI agent generates through the MCP tools actually lives: custom Gutenberg blocks, custom Elementor widgets, and PHP snippets. Everything is isolated under wp-content/emcp-sandbox, never your theme, WordPress core, or another plugin, and every artifact is created inactive. A human has to review and activate it before it runs. That review step is the whole point: the AI never writes raw PHP or JS directly into your site.

EMCP Tools → Sandbox is a three-card overview (Blocks / Widgets / PHP Snippets), each opening its own management screen.

PillarTierWhat it is
BlocksProAI-generated custom Gutenberg blocks, compiled from a spec. Active blocks appear in the block editor inserter under “EMCP Custom.”
WidgetsProAI-generated custom Elementor widgets, sandboxed and shown in the panel under “Custom (EMCP).” Tool reference: Widget Builder.
PHP SnippetsFree (capability-gated)Small PHP snippets an AI agent can draft, run as a shortcode or on a hook, that stay inactive until reviewed.

This page covers the PHP Snippets tools (undocumented elsewhere) and the admin review workflow shared by all three pillars. For creating custom Elementor widgets, see Widget Builder; for custom Gutenberg blocks, the tool reference is below.

A snippet runs as a shortcode ([emcp_snippet id="N"]), on a WordPress hook, or both. Code is validated on every create/update and rejected if it trips a critical security finding, the findings come back so the agent can fix it. create-php-snippet always produces an inactive draft; it never runs until an admin activates it in the Sandbox.

ToolPurpose
emcp-tools/validate-php-snippetDry-run validation, no code is saved.
emcp-tools/create-php-snippetCreate a snippet as an inactive draft.
emcp-tools/update-php-snippetUpdate code/settings; re-validates. An active snippet is recompiled, or demoted to draft if it no longer passes.
emcp-tools/get-php-snippetReturn a snippet’s code, settings, and status.
emcp-tools/list-php-snippetsList snippets (id, title, status).
emcp-tools/delete-php-snippetDelete a snippet.

create-php-snippet / update-php-snippet input:

  • title — a label for the snippet.
  • code (required on create) — PHP code, no <?php tag needed, runs inside an isolated function. Use return or echo for shortcode output.
  • context"shortcode", "hook", or "both". Defaults to shortcode.
  • hook — the WordPress action to attach to when context is hook/both (e.g. wp_footer, init).
  • priority — hook priority, default 10.

Activation always requires a human, in the Sandbox UI, regardless of who created the draft.

Same shape as Widget Builder, for the block editor instead of Elementor: the agent submits a JSON spec plus an HTML template with {{control}} placeholders, never raw JS, and the plugin compiles a real block.

ToolPurpose
emcp-tools/list-block-control-typesList supported attribute types + template syntax, call first.
emcp-tools/validate-block-specDry-run the generator, no code saved.
emcp-tools/create-custom-blockGenerate a block as an inactive draft from a spec.
emcp-tools/update-custom-blockReplace a block’s spec, regenerate, re-validate.
emcp-tools/get-custom-blockReturn a block’s spec, generated code, and status.
emcp-tools/list-custom-blocksList generated blocks (id, title, block name, status).
emcp-tools/set-block-statusActivate or deactivate a block.
emcp-tools/delete-custom-blockDelete a block (record + sandbox files).

Template syntax matches the Widget Builder: {{attribute_name}} for values, {{#if name}}…{{/if}} for conditionals, {{#each repeater}}…{{/each}} for loops, every value escaped by its declared attribute type. A runtime safety net isolates compile failures, a malformed block is demoted to draft with a recorded error rather than breaking the block editor.

Each pillar’s management screen (Blocks, Widgets, PHP Snippets) shows a table of that pillar’s artifacts with the same core actions:

EMCP Tools → Sandbox overview, three cards for Blocks, Widgets, and PHP Snippets with active/draft counts

  • Activate / Deactivate — the human review gate. Nothing an agent creates runs until this happens.
  • Delete — removes the record and its sandbox files.
  • Export — download a .json bundle of the artifact.
  • Import a bundle — upload a .json bundle exported from another site (or from Export); imports always land as a new inactive draft.
  • View code — inspect the generated PHP/JS before deciding whether to activate it.

Sandbox Blocks management screen, a table of custom blocks with Activate/Deactivate, Delete, Export, and View code actions

If the EMCP Cloud module is connected, each pillar also gets:

  • Save to Cloud — back up an artifact to your EMCP Cloud account.
  • Cloud Library — browse and import artifacts you’ve saved from any of your connected sites into the current one, as a new inactive draft to review.
  • Publish — publish an artifact to the EMCP Marketplace for others to install.
  • Push update — publish a new version of something you already published; artifacts published before update-tracking existed self-heal to offer this on their first push.

These buttons, and the plain Export / Import a bundle buttons above, are calls to MCP tools an agent can also use directly: export-sandbox-artifact / import-sandbox-artifact for the general portable-bundle mechanism (no Cloud connection needed), and cloud-backup / cloud-pull / cloud-marketplace-list / cloud-marketplace-install for the Cloud-connected versions. Full tool reference: EMCP Cloud & Marketplace.

Creating, updating, activating, and deleting any Sandbox artifact requires manage_options plus unfiltered_html, the same bar as site-wide custom code. Read/validate tools require edit_posts.