@agentxin-ai/plugin-playwright-cli
v0.0.2
Published
`@agentxin-ai/plugin-playwright-cli` adds browser automation support to AgentXin agents by bootstrapping `@playwright/cli` inside the agent sandbox and teaching the agent how to use it through `sandbox_shell`. Instead of registering a standalone tool, the
Readme
AgentXin Plugin: Playwright CLI Middleware
@agentxin-ai/plugin-playwright-cli adds browser automation support to AgentXin agents by bootstrapping @playwright/cli inside the agent sandbox and teaching the agent how to use it through sandbox_shell. Instead of registering a standalone tool, the middleware prepares the sandbox runtime, injects Playwright usage guidance into the system prompt, and keeps playwright-cli commands aligned with a managed Chromium configuration.
Key Features
- Bootstraps
@playwright/cliglobally inside the sandbox on first use. - Installs the Chromium browser runtime required by
playwright-cli. - Writes embedded skill assets (
SKILL.mdplus reference docs) into the sandbox for agent self-guidance. - Appends a Playwright-specific system prompt so the agent uses
sandbox_shellwithplaywright-cliinstead of unsupported alternatives. - Re-checks bootstrap state before Playwright shell commands and re-installs automatically if the sandbox container was reset.
- Injects a managed config for
playwright-cli openso Chromium is used by default when no browser/config is specified. - Caps
playwright-cli openshell calls to a short timeout so the browser session starts quickly without blocking the workflow. - Validates agent drafts and warns when sandbox support or
SandboxShellis missing.
Installation
pnpm add @agentxin-ai/plugin-playwright-cli
# or
npm install @agentxin-ai/plugin-playwright-cliNote: Ensure the host service already provides
@agentxin-ai/plugin-sdk,@metad/contracts,@nestjs/common@^11,@nestjs/event-emitter,@langchain/core@^0.3,zod, andchalk. These are treated as peer/runtime dependencies in the host environment.
Quick Start
- Register the Plugin
Start AgentXin with the package in your plugin list:
The plugin registers the globalPLUGINS=@agentxin-ai/plugin-playwright-cliPlaywrightCliPluginModule. - Enable Sandbox Support
Turn on the agent sandbox feature for the team/agent that will run browser automation. - Add
SandboxShellon the Same Agent
This middleware relies on thesandbox_shelltool exposed by theSandboxShellmiddleware. - Add the Playwright Middleware
In the AgentXin console (or agent definition), add a middleware entry with strategyPlaywrightCLISkill. - Optionally Configure the Bootstrap Behavior
Example middleware block:{ "type": "PlaywrightCLISkill", "options": { "cliVersion": "latest", "skillsDir": "/workspace/.agentxin/skills/playwright-cli" } }
Configuration
| Field | Type | Description | Default |
| ----- | ---- | ----------- | ------- |
| cliVersion | string | Version of @playwright/cli to install globally in the sandbox. | "latest" |
| skillsDir | string | Path inside the sandbox where SKILL.md and reference files are written. | "/workspace/.agentxin/skills/playwright-cli" |
Runtime Behavior
- On first use, the middleware checks
/workspace/.agentxin/.playwright-cli-bootstrap.jsonto determine whether the sandbox is already bootstrapped. - If bootstrap is missing or outdated, it installs
@playwright/cli, installs Chromium viaplaywright-cli install chromium, writes skill assets, and refreshes the stamp file. - A managed config is written to
/workspace/.agentxin/playwright-cli/cli.config.jsonand is automatically injected intoplaywright-cli opencommands when the command does not already specify--browseror--config. - The middleware appends a system prompt that tells the agent to:
- use
playwright-clirather thanplaywrightornpx playwright - read the sandbox skill file before first use
- prefer headless, non-interactive workflows
- avoid
codegen, UI mode, andshow
- use
- When the agent calls
sandbox_shellwith a Playwright command, the middleware ensures bootstrap has completed before the command runs. - For
playwright-cli opencommands,timeout_secis automatically capped to15seconds so the shell call returns promptly after the browser is launched. If the shell call times out, the browser session may still remain active in the sandbox. - Non-Playwright
sandbox_shellcommands are passed through unchanged.
Validation Rules
The plugin contributes draft validation warnings in AgentXin when:
- the agent uses
PlaywrightCLISkillbut sandbox support is disabled - the agent uses
PlaywrightCLISkillwithoutSandboxShellon the same agent
Sandbox Assets
During bootstrap, the plugin writes the following assets into the sandbox:
SKILL.mdwith recommendedplaywright-clicommand patterns- reference documents for advanced topics such as session management, request mocking, tracing, storage state, video recording, test generation, and running custom code
- a managed Playwright config that pins default browser startup to Chromium
- a bootstrap stamp file used to avoid unnecessary reinstallation
Configuration Precedence
Configuration is resolved in this order, from lowest to highest priority:
- Built-in defaults
- Environment variables:
PLAYWRIGHT_CLI_VERSIONPLAYWRIGHT_SKILLS_DIR
- Plugin-level config resolved by the host plugin config resolver
- Middleware
options
Development & Testing
NX_DAEMON=false pnpm -C /path/to/agentxin-plugins/agentxinai exec nx build @agentxin-ai/plugin-playwright-cli
NX_DAEMON=false pnpm -C /path/to/agentxin-plugins/agentxinai exec nx test @agentxin-ai/plugin-playwright-cliTypeScript output is emitted to middlewares/playwright-cli/dist.
License
This project follows the AGPL-3.0 License located at the repository root.
