Run OpenClaw in a Daytona Sandbox via SDK
This guide shows how to run OpenClaw inside a Daytona sandbox using the Daytona SDK. The script automatically creates and configures a sandbox with OpenClaw and provides an authenticated preview URL for using OpenClaw in the browser.
1. Workflow Overview
When you run the script, it creates a Daytona sandbox, starts the OpenClaw gateway inside it, and prints a preview link for the dashboard:
$ npm startCreating Daytona sandbox...Configuring OpenClaw...Starting OpenClaw...(Ctrl+C to shut down and delete the sandbox)
๐ Secret link to Control UI: https://18789-xxxx.proxy.daytona.works?token=...Open the provided link in your browser to connect to the OpenClaw Control UI. This link contains a configuration token, and anyone can use it to connect to OpenClaw without device approval.
You can use the Control UI to chat with your assistant, configure Telegram and WhatsApp, and manage sessions. When you exit the script (Ctrl+C), the sandbox will not be deleted unless sandbox persistence is disabled.
2. Project Setup
Clone the Repository
Clone the Daytona repository and go to the example directory:
git clone https://github.com/daytonaio/daytona.gitcd daytona/guides/typescript/openclawConfigure Environment
Get your API key from the Daytona Dashboard.
Copy .env.example to .env and add your Daytona API key:
DAYTONA_API_KEY=your_daytona_keyA default OpenClaw configuration is stored in openclaw.json. You can customize it according to the configuration reference. You can also add additional environment variables to .env.sandbox (e.g. ANTHROPIC_API_KEY for Claude) and they will be loaded into the sandbox.
Run the Example
Install dependencies and run:
npm installnpm startThe script creates the sandbox, starts the OpenClaw gateway, and prints a secret link with the token in the URL.
3. How It Works
- The script creates a Daytona sandbox with
DAYTONA_SNAPSHOT(e.g.daytona-medium) and loads env vars from.env.sandbox. - Your local
openclaw.jsonis merged with built-in config and written to~/.openclaw/openclaw.jsonin the sandbox. - The OpenClaw gateway is started inside the sandbox on
OPENCLAW_PORTvia process execution. - A signed preview link is generated and the token is appended as
?token=...; this link is printed so you can open the Control UI. - On Ctrl+C, the sandbox is deleted unless
PERSIST_SANDBOXistrue.
4. Key Constants
You can change behavior by editing the constants in src/index.ts:
| Constant | Default | Description |
|---|---|---|
PERSIST_SANDBOX | true | When true, the sandbox is not deleted when the script exits |
MAKE_PUBLIC | true | Allow anyone to access the sandbox instead of limiting to your Daytona organization |
OPENCLAW_PORT | 18789 | OpenClaw Gateway and Control UI port |
SHOW_LOGS | true | Stream OpenClaw stdout/stderr to the terminal |
Key advantages:
- Secure, isolated execution in a Daytona sandbox
- No device approval โ token in URL and
allowInsecureAuthskip pairing - Control UI and channels accessible via the secret preview link
- Optional: keep the sandbox running after exit (
PERSIST_SANDBOX)