Factory Droid
Make Factory Droid wait for a person's yes before every shell command, file change, web fetch, subagent and MCP tool call: a PreToolUse hook set up in one command that never widens Droid's autonomy level, verified in Droid 1.17.2.
Factory’s Droid decides by itself which commands it may run: its autonomy level (--auto low, medium or high) lets through anything the model rates at or below that risk. The model does the rating. Droid also runs a PreToolUse hook before each tool call, as Claude Code does. With the VariantGate hook there, every shell command, file change, web fetch, subagent and MCP tool call also waits for a person, who answers from the inbox, a phone notification, Slack or email. Rules answer the routine ones, and every answer lands on the same record as your other agents.
The quick way: one command
With Node.js on the computer it runs on, this does both steps for you. It opens the browser to sign in (or to make your free account), saves an agent key on this computer, and adds the approval hook to ~/.factory/settings.json, keeping the old file beside it:
npx -y https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz setup droidStart a new Droid session and ask it to run echo hello: the command waits until you approve it in the inbox, and so does every file change, web fetch, subagent and MCP tool call. A no blocks that one call. A file it cannot change safely, such as one with comments or one that links elsewhere, is left alone, and the command prints the entry to add yourself. The steps below do the same by hand.
1. Create a key
Sign in, open Agents and create a key for Droid. Copy it: it is shown once. Put it in your shell profile, such as ~/.zshrc, as export VARIANTGATE_KEY=….
2. Add the hook
Install the variantgate command (more on the SDK page):
npm install -g https://variantgate.com/sdk/variantgate-agent-latest.tgzThe hook reads VARIANTGATE_KEY from the environment Droid starts in, or a key saved on this computer:
Or run variantgate login once on this computer instead. It opens the browser, you check a code and press Connect, and it saves a new agent key in ~/.config/variantgate/credentials.json, readable only by you. The hook uses that key, with the API address it was made for, whenever VARIANTGATE_KEY is not set. The MCP server still needs the key from step 1.
Add this to ~/.factory/settings.json, next to what is there:
{
"hooks": {
"PreToolUse": [
{
"matcher": "^(?!(?:Read|LS|Grep|Glob|ToolSearch|TaskOutput|TodoWrite|ExitSpecMode|ListAutomations|ListAutomationTemplates|ReadAutomation|computer_list|computer_service_accounts_list|loop_list)$).*$",
"hooks": [
{
"type": "command",
"command": "variantgate hook droid",
"timeout": 150
}
]
}
]
}
}Droid compares the matcher with the whole tool name. This one picks every tool but the ones that only look, list or plan: Read, LS, Grep, Glob, ToolSearch, TaskOutput, TodoWrite, ExitSpecMode, ListAutomations, ListAutomationTemplates, ReadAutomation, computer_list, computer_service_accounts_list, loop_list. Any other tool, including one a later version adds, waits for a yes. That includes Task, which starts a subagent: we could not run a subagent offline, so starting one is asked about too. Droid hands the hook the call on stdin:
{
"session_id": "adb8cfb3-…",
"cwd": "/home/ada/shop",
"permission_mode": "auto-low",
"hook_event_name": "PreToolUse",
"tool_name": "Execute",
"tool_input": {
"command": "npm test",
"riskLevel": "low",
"riskLevelReason": "Runs the test suite"
}
}Each call becomes a request with an action name that rules can match:
- shell.run
- An Execute call, with the command, Droid's risk level and the folder. The same name the Claude Code, Codex, Gemini CLI, Cursor, Copilot, Cline, OpenCode, Qwen Code and Kilo hooks use, so one rule covers them all.
- file.write
- A Create call, with the file's path and text.
- file.edit
- An Edit call.
- web.fetch
- A FetchUrl call, with the address.
- web.search
- A WebSearch call, with the query.
- mcp.<server>.<tool>
- A call to an MCP tool, which Droid names <server>___<tool>: mcp.my-shop.refund_order for my-shop___refund_order.
- tool.<name>
- Any other tool, such as tool.Task for a subagent, tool.Skill, tool.CreateAutomation, or one a later Droid version adds.
What a yes and a no do
A no blocks that one call: the model gets the reason the person gave as the tool’s result, and the session goes on. A yes adds nothing to what Droid already allows. In our runs a hook’s allow made Droid skip its own autonomy check: under --auto low, a command the model rated high risk ran once a hook said allow. So on a yes the VariantGate hook prints nothing, and Droid’s own level still applies. Under --auto low, a high-risk command a person approved was still refused by Droid. Pick the --auto level for the commands Droid may run at all; the inbox then decides which of those it does.
What Droid does when a hook fails
We ran the hook in Droid 1.17.2 with droid exec, against a scripted model and a local copy of the service:
- Droid runs the call when a hook passes its timeout, exits with any code but 0 or 2, or prints something that is not JSON. A hook with no
timeoutgot about a minute. So setup writes a timeout of 150 seconds, which Droid waits for, and the hook always answers inside it. - It waits
VARIANTGATE_DROID_HOOK_WAITseconds for a person (100 by default, never more than 110), then withdraws the request and denies the call. Droid ignores a hook’senvfield, so set the variable in the environment Droid starts in. - If the service cannot be reached the hook denies the call. With no key set or saved it exits with code 2, which Droid reads as a no.
- The gap is a hook that cannot start or crashes: Droid then runs the call. Install the
variantgatecommand so the hook does not depend on npx, and after you change the settings, run one call and check that it is asked about.
MCP tool names
Droid names an MCP tool after its server and the tool, joined by three underscores, and saves a server under a name of its own: droid mcp add my.shop … saved it as my-shop, and its tool refund_order reached the hook as my-shop___refund_order. The hook splits the name at the first ___, so the request was asked as mcp.my-shop.refund_order, the same kind of action the other hooks send. A name with ___ more than once, or with more underscores around it, is asked under the whole name, so no rule for one server can match another’s tools. Write rules for the server name in ~/.factory/mcp.json, not the one you typed. Droid loads MCP tools through its ToolSearch tool, which only looks and is not asked about.
The hook puts every call in front of a person, including calls to the approvals MCP server if you add it to Droid as well, so use one or the other.
In scripts and CI
droid exec has nobody at the terminal, so the hook is the whole approval step there. Give the run a key, install the variantgate command on the machine, and choose the --auto level for the commands it may run at all:
export VARIANTGATE_KEY=... # a key for this pipeline
droid exec --auto medium "Fix the failing test and push a branch"A run that waits for a person holds the pipeline for up to the wait. Plan for a no: the call is blocked and the model is told why, so the task may finish without doing it. Check the result rather than the exit code, which was 0 in our runs either way.
What we have not tested
We tested droid exec on macOS with a custom model. We have not tested the terminal app, a subagent’s own calls (subagents need Factory’s service), project settings in .factory, or Windows. Check one call there before you rely on it.
Check that it works
Start a new Droid session and ask it to run echo hello. A request appears in the inbox; deny it and check that hello was not printed. Then ask again and approve it.