Sessionboxer

Run Grok Build in Docker: a small image, a login that survives the container, and when to approve every tool

Grok Build in a container needs a login without a browser and a choice about approvals. How to set up both, and what its own sandbox does and does not cover.

A Sessionboxer session where the agent runs commands without permission prompts, inside its own container

You want to try xAI's Grok Build on a real repository. You would rather it did not run on your laptop with your SSH keys, your shell history and every other project in reach. So you put it in a Docker container, start it, ask for a small change, and the first thing you get back is this:

Not signed in. To authenticate without a browser, run:
  grok login --device-code

Alternatively, set the XAI_API_KEY environment variable or run `grok login` on a machine with a browser.

That message is fair. A container has no browser, and Grok Build keeps its login in a folder the container throws away when it exits. This post covers a small image, a login that lasts between runs, the approval setting that matters once nobody is watching, and what Grok Build's own sandbox adds. We checked the commands below against Grok Build 1.0.92 in a node:22-bookworm container. The flags come from grok help and from xAI's CLI reference.

A small image to start from

Grok Build is a terminal coding agent. You can use it as a full-screen TUI, as a one-shot command in scripts, or through the Agent Client Protocol from an editor. xAI offers an install script and an npm package. In a Dockerfile the npm package is the simpler of the two, because the binary lands under /usr/local/lib/node_modules and not in your home folder:

FROM node:22-bookworm
ENV GROK_DISABLE_AUTOUPDATER=1
RUN npm install -g @xai-official/grok@1.0.92
USER node
RUN mkdir -p /home/node/.grok
WORKDIR /work

Two lines need a word. GROK_DISABLE_AUTOUPDATER=1 is listed in xAI's settings reference and stops the agent from replacing itself while it runs. With a pinned version in the image, you decide when the agent changes, which also limits the kind of attack described in our post on coding agent auto-updates. The mkdir runs as the node user so that a Docker volume mounted there later is writable by the agent. Without it, Docker creates the folder as root and the login cannot be saved.

Build it and run it on the current folder:

docker build -t grok-box .
docker run --rm -it -v "$PWD:/work" -v grok-home:/home/node/.grok grok-box grok

Logging in without a browser

Grok Build keeps its configuration, sessions and credentials in ~/.grok, or in the folder named by GROK_HOME. The login itself is ~/.grok/auth.json. Because the command above mounts a named volume on that folder, you only need to log in once:

docker run --rm -it -v grok-home:/home/node/.grok grok-box grok login --device-auth

--device-auth (alias --device-code) prints a URL and a code. You open the URL on any machine with a browser, enter the code, and the container writes auth.json into the volume. xAI says Grok refreshes access tokens in the background and asks you to sign in again only when a token cannot be refreshed.

For CI, or if you pay for API usage and not a Grok subscription, pass an API key in place of the file:

docker run --rm -e XAI_API_KEY -v "$PWD:/work" grok-box grok -p "Explain the build setup in this repo"

Both forms are live credentials. Anyone who can read the volume can use your Grok login, and anything the agent runs can read XAI_API_KEY from its own environment. Keeping secrets away from your coding agent covers why that matters more once the agent approves its own commands.

Approvals once nobody is watching

By default Grok Build asks before it runs a tool. That is right when you sit in front of it. In a container you started for a long task, every prompt is a stop. The permissions page lists the modes. For unattended runs the documented switch is --always-approve, with --yolo as an alias:

docker run --rm -it -v "$PWD:/work" -v grok-home:/home/node/.grok grok-box grok --always-approve

xAI notes that deny rules and PreToolUse hooks still apply in this mode, so you can still pass --deny rules for things you never want run. For scripts there is also --permission-mode dontAsk. The enterprise page describes it as silently denying anything without an explicit allow rule, and suggests it for headless and CI runs. That suits a job with a known set of commands. For open-ended work, expect it to deny steps you did not list.

One more check before you approve everything. A project's .grok/config.toml can add three things: [mcp_servers], [plugins] and [permission] rules, per the same permissions page. A repository you just cloned can therefore start MCP servers and add permission rules. Run grok inspect in the folder first. It shows the configuration Grok discovers for that directory. Codex has a similar issue with project config, which we wrote up in codex exec --trust and project config.

What Grok Build's own sandbox adds

Grok Build has its own sandbox, set with --sandbox <profile> or GROK_SANDBOX. It uses Landlock on Linux and Seatbelt on macOS, and it is off by default. The built-in profiles are off, workspace, devbox, read-only and strict. The workspace profile allows writes to the working folder, ~/.grok and temp.

xAI documents two limits. Permissions decide whether a tool call runs, and the sandbox limits what an approved call can reach. Also, the built-in profiles do not protect paths such as ~/.ssh permanently. You need a custom profile with a deny list for that.

Inside Docker, the container is already the main wall. It only sees the folders you mount, and it has no SSH keys unless you give it some. Landlock needs Linux 5.13 or newer, and a container uses the host's kernel, so whether the profile works depends on the machine. We did not test the profiles inside a container. If you turn one on, read the log: xAI says Grok writes a warning when it cannot enforce the sandbox.

The container does not limit the network. The agent can reach any host the machine can reach. If you add an allow list, the Grok kit for Docker Sandboxes names the hosts a subscription login needs: auth.x.ai for login and cli-chat-proxy.grok.com for inference. An API key talks to api.x.ai. That kit is another way to do all of this: sbx run --kit "git+https://github.com/docker/sbx-kits-contrib.git#dir=grok" grok runs Grok Build with --yolo in a Docker Sandbox, and an API key stored with sbx secret set xai stays in the sandbox proxy, outside the box.

What Sessionboxer does here

Sessionboxer runs Grok Build in a box per session: a Docker container on your machine or server, or a QEMU Windows or macOS virtual machine. You sign in once in the app with your own Grok account or an xAI API key, as described in Connect your agent. Each session then gets that login on its own, with your existing subscription and no new account.

Inside the box the agent starts with --always-approve, so it does not stop to ask. The box is the boundary: one box per session, with only that session's repository in it. The image pins a Grok Build version and turns its auto-updater off. The Grok login file sits in memory (tmpfs) behind ~/.grok/auth.json, and when Grok refreshes it during a session, Sessionboxer stores the refreshed file back.

Some things it does not do. It does not hide the login from the agent, because the agent needs it to work. It does not filter outbound network traffic. A Docker box shares the host's kernel, like any container. If you need a stronger wall, use a VM session. The Start a session chapter shows how to pick the environment.

If you would rather keep your own Dockerfile, the image above, a volume for ~/.grok, --always-approve and a quick grok inspect on each new repository get you most of the way.

Features mentioned

Keep reading