fix: pass Discord and Slack bot tokens via env vars into sandbox#601
Conversation
OpenClaw's Discord integration fails when it tries to write a user-provided bot token to openclaw.json, which is now immutable (root:root 444, Landlock read-only) after #588. OpenClaw already supports reading DISCORD_BOT_TOKEN and SLACK_BOT_TOKEN from environment variables, so we pass them through at sandbox creation time — the same pattern used for NVIDIA_API_KEY and TELEGRAM_BOT_TOKEN. Also disables channels.defaults.configWrites in the build-time config to prevent any channel plugin from attempting runtime writes to the immutable config file. Closes #599
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughDocker build now injects an extra Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer/CLI
participant Cred as Credential Store (getCredential)
participant Docker as Docker build
participant Sandbox as Sandbox (openshell)
participant VM as Brev VM
participant OpenClaw as OpenClaw runtime
Dev->>Docker: build image (inline python -> openclaw.json)
Docker-->>OpenClaw: image with configWrites: False
Dev->>Cred: request DISCORD_BOT_TOKEN / SLACK_BOT_TOKEN
Cred-->>Dev: token (if present)
Dev->>Sandbox: createSandbox(...) with envArgs (include tokens)
Sandbox->>OpenClaw: start runtime with env vars
Dev->>VM: deploy(instance) -> generate .env (include tokens)
VM->>OpenClaw: start service with .env environment
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
| | **Static** | Edit `openclaw-sandbox.yaml` and re-run `nemoclaw onboard`. | Persists across restarts. | | ||
| | **Dynamic** | Run `openshell policy set <policy-file>` on a running sandbox. | Session only; resets on restart. | | ||
|
|
||
| NemoClaw includes preset policy files for common integrations such as PyPI, Docker Hub, Slack, and Jira in `nemoclaw-blueprint/policies/presets/`. Apply a preset as-is or use it as a starting template. |
There was a problem hiding this comment.
Technically outside this diff, but should we add the Discord preset here as well? I realize there may be a fair bit of churn in that area right now.
(At least I assume there is a preset, based on #585 which might do well with another look with this merged)
There was a problem hiding this comment.
Good point, thx for flagging
There was a problem hiding this comment.
Added discord support to the PR as well.
Keep main's shellQuote usage for Telegram token, mkdtempSync for temp files, and "default policy" wording in README. Add Discord/Slack token passthrough on top.
Add discord.com, gateway.discord.gg, and cdn.discordapp.com to the baseline sandbox policy so Discord integration works without needing the preset applied separately.
|
Reviewed the latest rebase and validated the end-to-end path locally. What I checked:
Validation status:
Net: this preserves the immutability hardening from Let it rip 🤙 |
|
@ericksoa @kjw3 any chance if the below error be fixed for all so that everthig works please help why i am getting this error ◇ Configure Discord channels access? this is inside the sandbox |
|
@heartsiddharth1 This fix is already merged, but it changes how you set up Discord. Instead of configuring it inside the sandbox via export DISCORD_BOT_TOKEN=your-token-here
nemoclaw onboardThe token gets passed into the sandbox as an environment variable and OpenClaw picks it up automatically. Running To change the token later, you'll need to recreate the sandbox with the new token set. We know that's not ideal — tracking a better workflow for runtime credential updates as a follow-up. |
RISKY CHANGE — migration path to standardize messaging configuration. When messaging tokens (Telegram, Discord, Slack) are detected at onboard completion, automatically start the host-side bridges via start-services.sh. This seamlessly migrates users from the in-sandbox OpenClaw plugin path (#601) to the host-side bridge architecture. Discord and Slack enforce single gateway connections per token, so the host bridge naturally takes over from the in-sandbox plugin. The env var passthrough is kept for backwards compatibility during this transition.
…ixes NVIDIA#606) openclaw.json is locked (root:root 444) at build time to prevent agent tampering (NVIDIA#514, NVIDIA#588). However, users legitimately need to modify config at runtime — e.g. running `openclaw onboard` to add a Discord bot token. The atomic write (tmp → copyfile → rename) in OpenClaw's config writer fails with EACCES against the immutable file. PR NVIDIA#601 addressed the env-var path (passing DISCORD_BOT_TOKEN into the sandbox), but the underlying issue remains: any `openclaw onboard` or `/config` write inside the sandbox hits the same EACCES error. Fix: at sandbox startup, copy the immutable openclaw.json to the writable state directory (~/.openclaw-data/) and set OPENCLAW_CONFIG_PATH to redirect all OpenClaw config reads/writes to the copy. The original immutable file stays intact as a read-only reference; the Landlock policy on /sandbox/.openclaw continues to protect it. Changes: - nemoclaw-start.sh: add prepare_writable_config() that copies the locked config to ~/.openclaw-data/openclaw.json and exports OPENCLAW_CONFIG_PATH; update print_dashboard_urls to respect the env var - e2e-test.sh: add test 11 verifying writable overlay works and immutable original stays untouched
…DIA#601) * docs: add community feedback invitation for policy presets * docs: link baseline policy reference to the YAML file on GitHub * fix: pass Discord and Slack bot tokens via env vars into sandbox OpenClaw's Discord integration fails when it tries to write a user-provided bot token to openclaw.json, which is now immutable (root:root 444, Landlock read-only) after NVIDIA#588. OpenClaw already supports reading DISCORD_BOT_TOKEN and SLACK_BOT_TOKEN from environment variables, so we pass them through at sandbox creation time — the same pattern used for NVIDIA_API_KEY and TELEGRAM_BOT_TOKEN. Also disables channels.defaults.configWrites in the build-time config to prevent any channel plugin from attempting runtime writes to the immutable config file. Closes NVIDIA#599 * fix: add Discord endpoints to default sandbox policy Add discord.com, gateway.discord.gg, and cdn.discordapp.com to the baseline sandbox policy so Discord integration works without needing the preset applied separately.
…DIA#601) * docs: add community feedback invitation for policy presets * docs: link baseline policy reference to the YAML file on GitHub * fix: pass Discord and Slack bot tokens via env vars into sandbox OpenClaw's Discord integration fails when it tries to write a user-provided bot token to openclaw.json, which is now immutable (root:root 444, Landlock read-only) after NVIDIA#588. OpenClaw already supports reading DISCORD_BOT_TOKEN and SLACK_BOT_TOKEN from environment variables, so we pass them through at sandbox creation time — the same pattern used for NVIDIA_API_KEY and TELEGRAM_BOT_TOKEN. Also disables channels.defaults.configWrites in the build-time config to prevent any channel plugin from attempting runtime writes to the immutable config file. Closes NVIDIA#599 * fix: add Discord endpoints to default sandbox policy Add discord.com, gateway.discord.gg, and cdn.discordapp.com to the baseline sandbox policy so Discord integration works without needing the preset applied separately.
Summary
DISCORD_BOT_TOKENandSLACK_BOT_TOKENas env vars into the sandbox at creation timechannels.defaults.configWritesin the build-timeopenclaw.jsonto prevent channel plugins from writing to the immutable configdiscord.com,gateway.discord.gg,cdn.discordapp.com) to the default baseline sandbox policyContext
PR #588 made
openclaw.jsonimmutable to prevent agent tampering with gateway auth tokens. Community users reported that OpenClaw's Discord integration fails because it tries to write the bot token to the now-immutable config.OpenClaw already supports reading
DISCORD_BOT_TOKENfrom an environment variable and auto-enables the Discord channel when present. This PR passes the token through at sandbox creation time — the same pattern already used forNVIDIA_API_KEYandTELEGRAM_BOT_TOKEN.Closes #599
Closes #606
Test plan
DISCORD_BOT_TOKENenv var, run onboard, verify token is available inside sandboxopenclaw.jsonremains immutable (root:root, 444)