You can now use createCodingAgent to develop your own coding agent with all the essentials it needs. Configure it with a model, instructions, and memory. It can read files, run commands, fix bugs, and track its own progress.
If you're building a coding agent, the createCodingAgent helper starts you off with the right primitives: a sandbox for reading and writing files, a task list the agent can work through and complete, and a goal-judge prompt to validate the changes. Agents created with createCodingAgent are like any other Mastra agent, they work with AgentController, and use the same primitives Mastra Code runs on.
Use the buildBasePrompt to define your agent's behavior. Point it at your repo with projectPath, and set a branch using gitBranch. Use a mode to plan and propose changes, or build when it should implement them. Pass instructions as a function that accesses requestContext to modify behavior per request.
The createCodingAgent defaults can be customized — swap the workspace, replace the error processors, add your own signals, or modify the judge prompt. For additional functionality, you can drop in Mastra's built-in tools — web search, URL fetch, and ask-user prompts.
Get started
Install @mastra/core and @mastra/memory:
npm install @mastra/core @mastra/memory@mastra/core@1.48.0 or later, added in PR #18695.Configure the agent with a model and memory. Build instructions dynamically per request, reading values from requestContext:
import { buildBasePrompt, createCodingAgent } from "@mastra/core/coding-agent";
import { webSearchTool, webFetchTool, askUserTool } from "@mastra/core/tools";
import { Memory } from "@mastra/memory";
export const codingAgent = createCodingAgent({
id: "coding-agent",
name: "Coding Agent",
instructions: ({ requestContext }) => {
const mode = (requestContext.get("mode") as string) ?? "build";
const projectPath = (requestContext.get("projectPath") as string) ?? process.cwd();
const projectName = (requestContext.get("projectName") as string) ?? "my-app";
const gitBranch = (requestContext.get("gitBranch") as string) ?? "main";
return buildBasePrompt({
mode,
projectPath,
projectName,
gitBranch,
modelId: "anthropic/claude-sonnet-4.6",
productName: "Acme Coder",
coAuthorName: "Acme Bot",
coAuthorEmail: "bot@acme.dev"
});
},
defaultOptions: {
maxSteps: 50
},
model: "anthropic/claude-sonnet-4.6",
memory: new Memory(),
tools: { webSearchTool, webFetchTool, askUserTool }
});Customize the sandbox
The default LocalSandbox runs commands on the host machine. Swap in a remote sandbox like E2B when the agent needs isolation:
import { createCodingAgent } from "@mastra/core/coding-agent";
import { LocalFilesystem, Workspace } from "@mastra/core/workspace";
import { E2BSandbox } from "@mastra/e2b";
export const codingAgent = createCodingAgent({
// ...
workspace: new Workspace({
filesystem: new LocalFilesystem({ basePath: process.cwd() }),
sandbox: new E2BSandbox()
})
});Customize task tracking
With memory configured, the default TaskSignalProvider is added to any signals you pass. Task tracking remains enabled when you pass your own signal providers:
import { createCodingAgent } from "@mastra/core/coding-agent";
import { WebhookSignalProvider } from "@mastra/core/signals";
import { Memory } from "@mastra/memory";
export const codingAgent = createCodingAgent({
// ...
memory: new Memory(),
signals: [
new WebhookSignalProvider({
extractResourceId: (payload) => (payload as { repository: string }).repository
})
]
});Customize error retries
The default retry stack handles ECONNRESET, bad-request errors, and prefill/history compatibility. Replace it with your own StreamErrorRetryProcessor to tune retry counts, delays, or matchers:
import { createCodingAgent } from "@mastra/core/coding-agent";
import { StreamErrorRetryProcessor } from "@mastra/core/processors";
export const codingAgent = createCodingAgent({
// ...
errorProcessors: [
new StreamErrorRetryProcessor({
retryUnknownErrors: true,
maxRetries: 5,
delayMs: ({ retryCount }) => Math.min(1000 * 2 ** retryCount, 30000)
})
]
});Customize the goal judge
Customize the goal with your own judge model, run budget, and prompt instructions:
import { createCodingAgent } from "@mastra/core/coding-agent";
export const codingAgent = createCodingAgent({
//...
goal: {
judge: "anthropic/claude-haiku-4.5",
maxRuns: 50,
prompt: "Return `complete` when the code compiles and tests pass."
}
});For more information and full configuration options, see:
