Spawn an agent in an isolated subprocess with token isolation {project-root}/_bmad/core/config.yaml {project-root}/_bmad/bmm/config.yaml:token_management {project-root}/_bmad/_config/agent-manifest.csv {project-root}/_bmad-output Verify agent_type is valid (exists in {agent_manifest}) Verify prompt is not empty Set default model to "sonnet" if not specified Validate output_file path: Reject if output_file is an absolute path outside {output_dir} Reject if output_file contains path traversal sequences (../, ..\, or encoded variants) Canonicalize path: resolve to absolute path under {output_dir} Verify canonicalized path starts with {output_dir} (is descendant) If canonicalized path is not under {output_dir}: HALT with error: "output_file must be under {output_dir}; path traversal not allowed" If file already exists AND allow_overwrite == false: HALT with error: "output_file already exists; set allow_overwrite=true to overwrite" Load agent persona from {agent_manifest} for {agent_type} Load any agent customizations from {output_dir}/../_bmad/_config/agents/{agent_type}/ Build base_prompt by combining: - Agent persona and role description - Agent-specific customizations (if any) - User-provided {prompt} parameter Set resolved_output_file = {output_file} Set resolved_output_file = {output_dir}/temp/{agent_type}-{timestamp}.md Ensure parent directory of resolved_output_file exists Construct final_prompt by appending to base_prompt: " ## Output Instructions Write your complete output to: {resolved_output_file} Return only a brief summary (under 500 words) to this conversation." Use Task tool with: - description: "{agent_type}: {task_description}" - prompt: {final_prompt} - subagent_type: "general-purpose" - model: {model} - run_in_background: {run_in_background} final_prompt includes persona + task + output instructions with resolved_output_file Wait for agent completion Return agent_id for later retrieval Return structured output: - status: "success" | "failed" | "running" - agent_id: (if background) - output_file: {resolved_output_file} - summary: (agent's brief response)