Skip to content

Commit 255e606

Browse files
authored
fix: pass Discord and Slack bot tokens via env vars into sandbox (#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 #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 * 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.
1 parent 3846613 commit 255e606

4 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎Dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ config = { \
116116
'models': [{'id': model, 'name': model, 'reasoning': False, 'input': ['text'], 'cost': {'input': 0, 'output': 0, 'cacheRead': 0, 'cacheWrite': 0}, 'contextWindow': 131072, 'maxTokens': 4096}] \
117117
} \
118118
}}, \
119+
'channels': {'defaults': {'configWrites': False}}, \
119120
'gateway': { \
120121
'mode': 'local', \
121122
'controlUi': { \

‎bin/lib/onboard.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,14 @@ async function createSandbox(gpu) {
447447
if (process.env.NVIDIA_API_KEY) {
448448
envArgs.push(`NVIDIA_API_KEY=${shellQuote(process.env.NVIDIA_API_KEY)}`);
449449
}
450+
const discordToken = getCredential("DISCORD_BOT_TOKEN") || process.env.DISCORD_BOT_TOKEN;
451+
if (discordToken) {
452+
envArgs.push(`DISCORD_BOT_TOKEN=${shellQuote(discordToken)}`);
453+
}
454+
const slackToken = getCredential("SLACK_BOT_TOKEN") || process.env.SLACK_BOT_TOKEN;
455+
if (slackToken) {
456+
envArgs.push(`SLACK_BOT_TOKEN=${shellQuote(slackToken)}`);
457+
}
450458

451459
// Run without piping through awk — the pipe masked non-zero exit codes
452460
// from openshell because bash returns the status of the last pipeline

‎bin/nemoclaw.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ async function deploy(instanceName) {
158158
if (ghToken) envLines.push(`GITHUB_TOKEN=${shellQuote(ghToken)}`);
159159
const tgToken = getCredential("TELEGRAM_BOT_TOKEN");
160160
if (tgToken) envLines.push(`TELEGRAM_BOT_TOKEN=${shellQuote(tgToken)}`);
161+
const discordToken = getCredential("DISCORD_BOT_TOKEN");
162+
if (discordToken) envLines.push(`DISCORD_BOT_TOKEN=${shellQuote(discordToken)}`);
163+
const slackToken = getCredential("SLACK_BOT_TOKEN");
164+
if (slackToken) envLines.push(`SLACK_BOT_TOKEN=${shellQuote(slackToken)}`);
161165
const envDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-env-"));
162166
const envTmp = path.join(envDir, "env");
163167
fs.writeFileSync(envTmp, envLines.join("\n") + "\n", { mode: 0o600 });

‎nemoclaw-blueprint/policies/openclaw-sandbox.yaml‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ network_policies:
158158
- { path: /usr/local/bin/npm }
159159

160160
# ── Messaging — pre-allowed for agent notifications ────────────
161-
# Telegram Bot API is open by default so the agent can send
161+
# Telegram and Discord are open by default so the agent can send
162162
# notifications and respond to chats without triggering approval.
163163
telegram:
164164
name: telegram
@@ -171,3 +171,30 @@ network_policies:
171171
rules:
172172
- allow: { method: GET, path: "/bot*/**" }
173173
- allow: { method: POST, path: "/bot*/**" }
174+
175+
discord:
176+
name: discord
177+
endpoints:
178+
- host: discord.com
179+
port: 443
180+
protocol: rest
181+
enforcement: enforce
182+
tls: terminate
183+
rules:
184+
- allow: { method: GET, path: "/**" }
185+
- allow: { method: POST, path: "/**" }
186+
- host: gateway.discord.gg
187+
port: 443
188+
protocol: rest
189+
enforcement: enforce
190+
tls: terminate
191+
rules:
192+
- allow: { method: GET, path: "/**" }
193+
- allow: { method: POST, path: "/**" }
194+
- host: cdn.discordapp.com
195+
port: 443
196+
protocol: rest
197+
enforcement: enforce
198+
tls: terminate
199+
rules:
200+
- allow: { method: GET, path: "/**" }

0 commit comments

Comments
 (0)