Back to blog posts
Blaxel News

5 min

How to run OpenClaw safely in a Blaxel sandbox

Learn how to set up an OpenClaw sandbox in Blaxel, from a Node image to Gateway pairing, keeping the agent away from your files.

Vikram VaswaniVikram Vaswani is a developer advocate at Blaxel. He is an active open source community member and developer, with deep experience in cloud-native application development and infrastructure. He is the author of seven technical books on programming and databases, published internationally and translated into multiple languages.

OpenClaw, the AI agent formerly known as Clawdbot and Moltbot, runs directly on the machine it's on. That reach makes it useful. It also means a bad prompt can touch your real files and credentials. The public record already includes a CVE that leaked the Gateway token.

The safer way to run OpenClaw is to give it its own machine. A Blaxel sandbox is an isolated environment that is created in under a second and resumes from standby in under 25ms. If the agent misbehaves, the sandbox limits what it can reach. You delete it and start fresh.

This tutorial takes you from a fresh sandbox to an OpenClaw Gateway you can open in your browser, allowedOrigins setting included.

Key takeaways

  • OpenClaw runs directly on the machine it's installed on. A bad prompt can reach your real files and credentials. A flaw like CVE-2026-25253 leaked the Gateway token.
  • OpenClaw's own sandbox mode is off by default. When you turn it on, it moves only tool execution, while the Gateway stays on the host.
  • Running all of OpenClaw inside a Blaxel sandbox puts the Gateway and every tool in a Firecracker microVM. You can delete it if the agent misbehaves.
  • The microVM boundary protects only what stays outside it. Give OpenClaw a separate model API key, and never copy SSH keys or cloud credentials into the sandbox.

Here's the short version of how to run OpenClaw safely in a sandbox:

StageCommandWhat it does
1bl new sandbox openclaw-node, then bl pushBuilds a Node 24.22.1 sandbox image after you edit the FROM line
2python main.pyCreates the sandbox, a private preview URL for port 18789, and a 24-hour preview token
3npm install -g openclaw@latest --allow-scripts=openclawInstalls OpenClaw inside the sandbox
4openclaw onboardSets up your model provider and the Gateway token
5jq edit, then openclaw gateway --bind lan --verboseAdds the preview URL to gateway.controlUi.allowedOrigins and starts the Gateway
6openclaw devices approve <requestId>Approves your browser after you paste the Gateway token

The Register and ZDNet covered the security worries. Those worries include CVE-2026-25253, which leaked the Gateway token (OpenClaw's control server). Kaspersky reports a CVSS score of 8.8 for that flaw and a patch in release 2026.1.29. Microsoft's security guidance recommends a dedicated virtual machine.

I ran all of OpenClaw, including the Gateway, inside a Blaxel sandbox.

After some trial and error and help from Blaxel's engineering team, I got OpenClaw running. Later, I had it chatting with me on Discord. This setup gets you to a working chat in the browser.

Here's what you need to get started:

With those ready, start by creating the sandbox.

1. Create a sandbox

1. Download and install the Blaxel CLI and log in to your Blaxel account:

Shell
bl login

Logging in lets the SDK connect to your workspace locally without extra setup. If you run your code from a remote server instead, set the BL_WORKSPACE and BL_API_KEY environment variables.

2. In a new directory, install the Blaxel Python SDK:

Shell
python3 -m venv .venv
source .venv/bin/activate
pip install blaxel

3. Build a Node 24 sandbox image.

OpenClaw's Node docs recommend Node 24.22.1+ or 26.12.1+. The current release, 2026.10.8, makes those versions mandatory in its package engines field.

Blaxel's blaxel/node:latest template ships Node.js 23, so build a custom image:

Shell
bl new sandbox openclaw-node
cd openclaw-node

If the CLI asks for a template, choose an Alpine-based one, because the FROM line below uses Alpine. In the generated Dockerfile, change the FROM line as shown below.

Keep the COPY line for Blaxel's sandbox-api binary, which every custom image needs:

Docker
FROM node:24.22.1-alpine

Push the image, then print its ID:

Shell
bl push
bl get image sandbox/openclaw-node --latest

Replace IMAGE_ID in the scripts below with that ID.

4. Go back to the directory where you installed the SDK and create a script named main.py:

Python
import asyncio
from datetime import datetime, timedelta, UTC

from blaxel.core import SandboxInstance

async def main():
# Create sandbox (returns the existing one if the name is taken)
sandbox = await SandboxInstance.create_if_not_exists({
"name": "openclaw-sandbox",
"image": "IMAGE_ID", # from bl get image
"memory": 4096,
"ports": [{ "target": 18789, "protocol": "HTTP" }],
"region": "us-pdx-1",
})

`# Create a private preview for the OpenClaw Gateway port`  
`preview = await sandbox.previews.create_if_not_exists({`  
    `"metadata": {"name": "openclaw-gateway"},`  
    `"spec": {`  
        `"port": 18789,`  
        `"public": False,`  
    `}`  
`})`

`# Create preview token, valid for 24 hours`  
`expires_at = datetime.now(UTC) + timedelta(days=1)`  
`token = await preview.tokens.create(expires_at)`

`# Print preview URL and token value`  
`print(f"Preview URL: {preview.spec.url}")`  
`print(f"Token: {token.value}")`  
`print(f"Browser URL: {preview.spec.url}?bl_preview_token={token.value}")`

if __name__ == "__main__":
asyncio.run(main())

This script:

  • creates a Blaxel sandbox named openclaw-sandbox from your Node 24 image.
  • declares port 18789, which OpenClaw uses for WebSocket and HTTP.
  • creates a private preview URL for the Gateway on that port.
  • generates an access token for the preview URL, valid for 24 hours.

Prefer TypeScript?

Install the TypeScript SDK with npm install @blaxel/core and use this equivalent main.ts:

TypeScript
import { SandboxInstance } from "@blaxel/core";

const sandbox = await SandboxInstance.createIfNotExists({
name: "openclaw-sandbox",
image: "IMAGE_ID", // from bl get image
memory: 4096,
ports: [{ target: 18789, protocol: "HTTP" }],
region: "us-pdx-1",
});

const preview = await sandbox.previews.createIfNotExists({
metadata: { name: "openclaw-gateway" },
spec: { port: 18789, public: false },
});

// Valid for 24 hours
const token = await preview.tokens.create(new Date(Date.now() + 86_400_000));

console.log(`Preview URL: ${preview.spec.url}`);
console.log(`Token: ${token.value}`);
console.log(`Browser URL: ${preview.spec.url}?bl_preview_token=${token.value}`);

The script uses top-level await, so run it as an ES module, for example with "type": "module" in package.json. Use any TypeScript runner that supports ES modules.

5. Run the script to create the sandbox and preview URL:

Shell
python main.py

Once complete, the script displays the generated preview URL (for example, https://b186....preview.bl.run) and preview token (for example, cbba622560db78e...). It also prints a browser URL that combines them. You'll need these values later.

2. Install and configure OpenClaw

1. Connect to the Blaxel sandbox terminal:

Shell
bl connect sandbox openclaw-sandbox

2. Check the Node.js and npm versions before installing anything:

Shell
node --version
npm --version

If Node is below 24.22.1, check that image in main.py holds your custom image ID. The script reuses any sandbox with the same name, so delete the old sandbox before re-running the script. Use bl delete sandbox openclaw-sandbox.

3. Run these commands to install OpenClaw in the sandbox:

Shell
apk add curl bash make cmake g++ build-base linux-headers jq
npm install -g openclaw@latest --allow-scripts=openclaw

The apk line matches Blaxel's OpenClaw tutorial. jq is for the config edit below. On npm 11.16+ and npm 12, OpenClaw's install command includes --allow-scripts=openclaw. Drop it on npm 11.15 and earlier. Node 24.22.1 ships npm 11.19.1, so keep it.

Confirm the install with:

Shell
openclaw --version
openclaw doctor

4. Configure OpenClaw:

Shell
openclaw onboard

Read the security notice first. The guided flow then asks for the first agent's name. Next, you choose whether the agent gets full access or asks for approval first. OpenClaw saves that choice as wizard.accessMode.

OpenClaw requires a primary model before you open agent chat, so pick one here. Then supply credentials (an API key or an existing CLI login). To walk through channels (such as Discord), skills, and other settings one at a time instead, run openclaw onboard --classic. To change settings later, run openclaw configure.

5. When configuration finishes, OpenClaw's status output usually reports that systemd services are unavailable. That's expected: for performance reasons, Blaxel sandboxes don't include the systemd process manager. You'll start the Gateway manually after setting the allowed origins.

6. Print the Gateway token.

You'll paste it into the Control UI later:

Shell
openclaw gateway auth-token --show

Onboarding stores it under gateway.auth.token. The command needs an interactive terminal and refuses piped output. Keep the token private, because it authorizes control of the agent.

3. Configure OpenClaw Gateway access

1. Add the preview URL to the allowed origins in the OpenClaw configuration file. The default path is ~/.openclaw/openclaw.json. In my sandbox, the file was at /blaxel/.openclaw/openclaw.json. Run ls ~/.openclaw to confirm yours.

In both examples below, replace https://b186....preview.bl.run with your own preview URL.

JSON
"gateway": {
"controlUi": {
"allowedOrigins": ["https://b186....preview.bl.run"]
},
// ...
}

Or make the same edit with jq, which sets only allowedOrigins and leaves other controlUi keys intact:

Shell
cd ~/.openclaw # or the directory you confirmed above
jq '.gateway.controlUi.allowedOrigins = ["https://b186....preview.bl.run"]' openclaw.json > openclaw.json.new && mv openclaw.json.new openclaw.json

See the allowedOrigins section below for the rules this value must follow.

2. Start the OpenClaw Gateway service manually and keep it running:

Shell
openclaw gateway --bind lan --verbose

Binding to lan makes the Gateway listen beyond loopback so that the preview URL can reach it. For non-loopback binds, OpenClaw requires auth and won't start without it. Here, the private preview URL and its token sit in front of the Gateway. The Gateway token adds a second check.

Confirm the logs show the Gateway starting and listening on port 18789.

Your model and PID will differ:

Shell
[gateway] agent model: <provider>/<model>
[gateway] listening on ws://0.0.0.0:18789 (PID <pid>)

Important: Leave this terminal open. The Gateway must keep running for the rest of the setup.

3. Open the browser URL that main.py printed, which is the preview URL with the token in its query string. It looks like https://b186....preview.bl.run?bl_preview_token=cbba.... The page displays the OpenClaw Control UI.

4. Paste the Gateway token into the Gateway secret field on the login screen.

5. The Control UI then shows disconnected (1008): pairing required. Each new browser or device needs a one-time pairing approval.

6. Connect to the sandbox terminal in a separate terminal window, so the Gateway process keeps running:

Shell
bl connect sandbox openclaw-sandbox

7. List the available pairing requests:

Shell
openclaw devices list

8. You'll usually see one pending pairing request. Approve it with the request ID from the list:

Shell
openclaw devices approve f06d4e9b...

9. Return to the browser tab. The page connects on its own once you approve the request.

How allowedOrigins and browser access work

Public, non-loopback deployments must set gateway.controlUi.allowedOrigins explicitly, using full origins. The Gateway may add local origins like http://localhost:<port> on its own. Remote browser origins, like a preview.bl.run URL, still need explicit entries.

  • Use the full origin: Include the scheme and host (https://b186....preview.bl.run), without the ?bl_preview_token= query string or any path.
  • Add one entry per origin you browse from: A custom domain needs its own entry beside the preview URL.
  • Skip ["*"]: It allows any browser origin, so OpenClaw reserves it for tightly controlled local testing.
  • Leave Host-header fallback off: OpenClaw labels gateway.controlUi.dangerouslyAllowHostHeaderOriginFallback=true a dangerous security mode.

Browser access to a private preview also needs the Blaxel preview token. Passing ?bl_preview_token= in the URL works for a first visit. Opening that URL once sets a cookie named bl_preview_token, which the browser sends with later credentialed requests.

Scripts and API clients can send the X-Blaxel-Preview-Token header instead. When the 24-hour token expires, re-run main.py to create a new one. The preview URL itself stays the same.

The OpenClaw sandbox browser is OpenClaw's own browser tool, which runs Chromium in a container. It needs the Docker engine backend. The SSH backend doesn't support it, and the OpenShell backend doesn't yet.

In the sandbox browser image, Chromium always launches with --no-sandbox --disable-setuid-sandbox. The Node image you built has no Docker engine, so this setup skips the sandbox browser.

4. Test OpenClaw

In the Control UI, open the Chat page and enter a prompt. A reply confirms that the OpenClaw agent works.

Note: In my testing, ending the interactive shell session stopped the Gateway. To keep the Gateway running without an active shell, stop the manual Gateway with Ctrl+C first. Both use port 18789.

Then save this script locally as start_gateway.py and run it:

Python
import asyncio

from blaxel.core import SandboxInstance

async def main():
# Get sandbox
sandbox = await SandboxInstance.get("openclaw-sandbox")

`# Start the Gateway as a managed process`  
`process = await sandbox.process.exec({`  
  `"name": "start-openclaw-gateway",`  
  `"command": "openclaw gateway --bind lan --verbose",`  
  `"restart_on_failure": True,`  
  `"max_restarts": 5,`  
  `"keep_alive": True, # stops auto-standby while the Gateway runs`  
  `"timeout": 0         # no auto-kill for keep_alive processes`  
`})`

if __name__ == "__main__":
asyncio.run(main())

Blaxel sandboxes move to standby after ~15 seconds without an active connection. They resume in under 25ms. Standby triggers on network inactivity, so a background process alone doesn't hold the sandbox active. The script sets keep_alive, which keeps the sandbox active while the process runs.

Keep-alive is in alpha. Blaxel kills a keep-alive process after 600 seconds unless you set a timeout, so the script sets timeout to 0. With the Gateway running this way, the sandbox stays active, and bills compute.

If the Gateway stops or restarts, stream its process logs to see why:

Shell
bl logs sandbox openclaw-sandbox start-openclaw-gateway --follow

OpenClaw sandbox mode vs. a Blaxel sandbox

OpenClaw's built-in sandbox and a Blaxel sandbox isolate different things. OpenClaw's sandboxing is off by default, and you configure it under agents.defaults.sandbox. When you turn it on, the Gateway process stays on the host.

Only tool execution moves into a sandbox backend. A Blaxel sandbox wraps the entire OpenClaw install, including the Gateway, its config file, and its stored tokens.

The mode key decides which sessions get tool-level isolation:

agents.defaults.sandbox.modeWhat runs sandboxed
off (default)No agent-wide sandboxing. Sessions whose creator role requires a sandbox still run sandboxed.
non-mainEvery session except the agent's main session. Group and channel sessions always count as non-main.
allEvery session.

If you connect Discord as I did, its channel sessions run sandboxed under non-main, but your main session doesn't.

The same block takes three more keys:

  • scope: agent (default), session, shared
  • workspaceAccess: none (default), ro, rw
  • backend: docker (default), podman, ssh, openshell, crabbox

Blaxel's docs also show how to run NVIDIA OpenShell on Blaxel, with each agent in its own microVM.

On a host with a supported backend, a minimal config looks like this:

Json5
{ agents: { defaults: { sandbox: { mode: "non-main", scope: "session", workspaceAccess: "none" } } } }

Inside the custom Node sandbox, leave mode off. OpenClaw then runs channel sessions without its own sandbox, but still inside the Blaxel microVM. The default Docker backend needs a Docker engine, and the Node image has none.

Blaxel also offers a blaxel/docker-in-sandbox:latest image. This walkthrough doesn't test OpenClaw's Docker backend there.

If you turn on OpenClaw's sandbox mode, these commands show what it's doing:

Shell
openclaw sandbox explain # effective mode, scope, workspace access, tool policy
openclaw sandbox list # runtimes, image match, idle time
openclaw sandbox recreate --all # apply image or setupCommand changes

Sandbox mode decides where tools run, and tool policy decides which tools are callable. The tools.elevated setting runs exec outside the sandbox. Sandboxing never restores a tool that policy denies.

As a result, a tight tool policy still limits what a prompt-injected Discord session can do inside the Blaxel sandbox.

Run OpenClaw safely in a Blaxel sandbox

A microVM boundary helps keep a prompt-injected OpenClaw away from your host's keys and files. The boundary holds only as long as those keys and files stay outside the microVM. Containers share the host kernel.

A shared kernel is a risk when you run untrusted code. Blaxel instead runs each sandbox in its own Firecracker microVM. The same technology behind AWS Lambda inspired the design. Give OpenClaw a separate model API key for experiments. Don't copy SSH keys or cloud credentials into the sandbox.

A dedicated virtual machine is another option for running OpenClaw away from your laptop. Unlike a VM, Blaxel sandboxes have no compute cost in standby, though the keep-alive Gateway prevents standby.

Standby keeps state but isn't durable storage. Store the config and workspace on a Blaxel Volume, which is persistent storage you attach to a sandbox.

FAQs about OpenClaw sandbox

What is an OpenClaw sandbox?

"OpenClaw sandbox" can mean two things. OpenClaw's built-in sandbox mode moves tool execution into a Docker, Podman, SSH, OpenShell, or Crabbox backend. The Gateway stays on the host. Running OpenClaw in a Blaxel sandbox puts the Gateway and every tool inside a microVM.

How do I sandbox OpenClaw?

Build a Node 24.22.1 sandbox image, then run main.py to create the sandbox and a private preview URL. Install OpenClaw with npm, run openclaw onboard, add the preview URL to gateway.controlUi.allowedOrigins, and start the Gateway with --bind lan. To also sandbox tools, set agents.defaults.sandbox.mode to non-main or all on a host with a supported backend.

What does gateway.controlUi.allowedOrigins do?

The setting lists the browser origins allowed to load the Control UI. Public, non-loopback deployments must set it with full origins, like https://b186....preview.bl.run. Leave out paths and query strings, and avoid ["*"] outside local testing.

Does the OpenClaw sandbox browser work in a Blaxel sandbox?

The sandbox browser doesn't work in this setup. It runs only on OpenClaw's Docker engine backend, and the custom Node image has no Docker engine.

Related articles