AIHero

    Running

    Prompts

    Edit this page on GitHub
    On this page

    A prompt template is a prompt that Sandcastle reads from a file and fills in before the agent sees it. This one, in .sandcastle/prompt.md, has a prompt argument, {{ISSUE_NUMBER}}, whose value you pass in promptArgs; a built-in prompt argument, {{SOURCE_BRANCH}}, which Sandcastle fills in for you; and a shell expression, a !`command` that Sandcastle runs in the sandbox and replaces with its output:

    Work on issue #{{ISSUE_NUMBER}}. You are on {{SOURCE_BRANCH}}.
    !`gh issue view {{ISSUE_NUMBER}} --json body -q .body`

    And the run() call that fills it in:

    import { run, claudeCode } from "@ai-hero/sandcastle";
    import { docker } from "@ai-hero/sandcastle/sandboxes/docker";
    await run({
    agent: claudeCode("claude-opus-4-8"),
    sandbox: docker(),
    promptFile: ".sandcastle/prompt.md",
    promptArgs: { ISSUE_NUMBER: 42 },
    });

    Sandcastle uses a flexible prompt system. You write the prompt, and the engine executes it — no opinions about workflow, issue tracking, or context sources are imposed.

    Prompt resolution

    You must provide exactly one of:

    1. prompt: "inline string" — pass an inline prompt, a prompt written as a string in your code, directly via RunOptions
    2. promptFile: "./path/to/prompt.md" — point to a specific file via RunOptions

    prompt and promptFile are mutually exclusive — providing both is an error. If neither is provided, run() throws an error asking you to supply one.

    Inline prompts (prompt: "...") are passed to the agent literally. No {{KEY}} substitution, no !`command` expansion, no built-in {{SOURCE_BRANCH}} / {{TARGET_BRANCH}} injection. If you need values interpolated into an inline prompt, build the string in JavaScript (`Work on ${branch}…`). Passing promptArgs alongside an inline prompt is an error — switch to promptFile to use substitution.

    The substitution and expansion features below apply only to prompts sourced from promptFile.

    Dynamic context with !`command`

    Use !`command` expressions in your prompt to pull in dynamic context. Each expression is replaced with the command's stdout before the prompt is sent to the agent. All expressions in a prompt run in parallel for faster expansion.

    Commands run inside the sandbox after sandbox.onSandboxReady hooks complete, so they see the same repo state the agent sees (including installed dependencies).

    # Open issues
    !`gh issue list --state open --label Sandcastle --json number,title,body,comments,labels --limit 100`
    # Recent commits
    !`git log --oneline -10`

    If any command exits with a non-zero code, the run fails immediately with an error.

    Shell expressions inside HTML comments (``) are not run; they reach the agent as written. Use a comment to keep an example or a disabled command in the prompt.

    Prompt arguments with {{KEY}}

    Use {{KEY}} placeholders in your prompt to inject values from the promptArgs option. This is useful for reusing the same prompt file across multiple runs with different parameters.

    import { run } from "@ai-hero/sandcastle";
    await run({
    promptFile: "./my-prompt.md",
    promptArgs: { ISSUE_NUMBER: 42, PRIORITY: "high" },
    });

    In the prompt file:

    Work on issue #{{ISSUE_NUMBER}} (priority: {{PRIORITY}}).

    Prompt argument substitution, the step that swaps each {{KEY}} for its value, runs on the host before shell expression expansion, so {{KEY}} placeholders inside !`command` expressions are replaced first:

    !`gh issue view {{ISSUE_NUMBER}} --json body -q .body`

    A {{KEY}} placeholder with no matching prompt argument is an error. Unused prompt arguments produce a warning.

    !`command` expansion only runs on shell blocks written in the prompt file itself. Any !`…` pattern that appears inside an argument value is treated as inert text — it won't be executed against the host shell. This makes it safe to pass user-authored content (issue titles, PR descriptions, docs excerpts) through promptArgs.

    Built-in prompt arguments

    Sandcastle automatically injects two built-in prompt arguments into every prompt:

    PlaceholderValue
    {{SOURCE_BRANCH}}The branch the agent works on (determined by the branch strategy)
    {{TARGET_BRANCH}}The host's active branch at run() time

    Use them in your prompt without passing them via promptArgs:

    You are working on {{SOURCE_BRANCH}}. When diffing, compare against {{TARGET_BRANCH}}.

    Passing SOURCE_BRANCH or TARGET_BRANCH in promptArgs is an error — built-in prompt arguments cannot be overridden.