Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bin/lib/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,22 @@ async function createSandbox(gpu) {
run(`cp -r "${path.join(ROOT, "scripts")}" "${buildCtx}/scripts"`);
run(`rm -rf "${buildCtx}/nemoclaw/node_modules"`, { ignoreError: true });

// If CHAT_UI_URL is set, bake it into the Dockerfile copy so the build-time
// config generator writes the correct allowedOrigins. Without this, remote
// browsers hit "origin not allowed".
// Ref: https://github.com/NVIDIA/NemoClaw/issues/795
const chatUiUrl = process.env.CHAT_UI_URL || 'http://127.0.0.1:18789';
if (chatUiUrl !== 'http://127.0.0.1:18789') {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the default URL is repeated as a magic string here and must match the Dockerfile ARG default. If the Dockerfile default ever changes, this comparison silently breaks. Consider extracting a constant:

Suggested change
const chatUiUrl = process.env.CHAT_UI_URL || 'http://127.0.0.1:18789';
if (chatUiUrl !== 'http://127.0.0.1:18789') {
const DEFAULT_CHAT_UI_URL = 'http://127.0.0.1:18789';
const chatUiUrl = process.env.CHAT_UI_URL || DEFAULT_CHAT_UI_URL;
if (chatUiUrl !== DEFAULT_CHAT_UI_URL) {

if (/^https?:\/\/[a-zA-Z0-9._:-]+(\/[a-zA-Z0-9._/~%-]*)?$/.test(chatUiUrl)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex is duplicated in scripts/setup.sh:198 (bash version). If one gets updated without the other, you get inconsistent validation depending on the entrypoint. Consider adding a comment in each location cross-referencing the other, e.g.:

// NOTE: keep in sync with scripts/setup.sh URL validation regex

const dfPath = path.join(buildCtx, "Dockerfile");
let df = fs.readFileSync(dfPath, "utf-8");
df = df.replace(/^ARG CHAT_UI_URL=.*/m, `ARG CHAT_UI_URL=${chatUiUrl}`);
fs.writeFileSync(dfPath, df);
} else {
console.log(" Warning: CHAT_UI_URL contains invalid characters — using default (localhost)");
}
}

// Create sandbox (use -- echo to avoid dropping into interactive shell)
// Pass the base policy so sandbox starts in proxy mode (required for policy updates later)
const basePolicyPath = path.join(ROOT, "nemoclaw-blueprint", "policies", "openclaw-sandbox.yaml");
Expand All @@ -554,7 +570,7 @@ async function createSandbox(gpu) {
// --gpu is intentionally omitted. See comment in startGateway().

console.log(` Creating sandbox '${sandboxName}' (this takes a few minutes on first run)...`);
const chatUiUrl = process.env.CHAT_UI_URL || 'http://127.0.0.1:18789';
// chatUiUrl was declared above (used for Dockerfile sed).
const envArgs = [`CHAT_UI_URL=${shellQuote(chatUiUrl)}`];
if (process.env.NVIDIA_API_KEY) {
envArgs.push(`NVIDIA_API_KEY=${shellQuote(process.env.NVIDIA_API_KEY)}`);
Expand Down
22 changes: 22 additions & 0 deletions docs/deployment/deploy-to-remote-gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ Run a test agent prompt inside the remote sandbox:
$ openclaw agent --agent main --local -m "Hello from the remote sandbox" --session-id test
```

## Remote Dashboard Access

The NemoClaw dashboard validates the browser origin against an allowlist baked
into the sandbox image at build time. By default the allowlist only contains
`http://127.0.0.1:18789`. When accessing the dashboard from a remote browser
(for example through a Brev public URL or an SSH port-forward), set
`CHAT_UI_URL` to the origin the browser will use **before** running setup:

```console
$ export CHAT_UI_URL="https://openclaw0-<id>.brevlab.com"
$ nemoclaw deploy <instance-name>
```

For SSH port-forwarding, the origin is typically `http://127.0.0.1:18789` (the
default), so no extra configuration is needed.

:::{note}
On Brev, set `CHAT_UI_URL` in the launchable environment configuration so it is
available when the setup script builds the sandbox image. If `CHAT_UI_URL` is
not set on a headless host, `brev-setup.sh` prints a warning.
:::

## GPU Configuration

The deploy script uses the `NEMOCLAW_GPU` environment variable to select the GPU type.
Expand Down
15 changes: 15 additions & 0 deletions scripts/brev-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ fi
# --- 5. Run setup.sh ---
# Use sg docker to ensure docker group is active (usermod -aG doesn't
# take effect in the current session without re-login)

# CHAT_UI_URL tells setup.sh which browser origin to allow in the gateway
# config. On Brev, the launchable config should set this to the public URL
# (e.g. https://openclaw0-<id>.brevlab.com). Without it the dashboard
# rejects remote browsers with "origin not allowed".
# Ref: https://github.com/NVIDIA/NemoClaw/issues/795
if [ -n "${CHAT_UI_URL:-}" ]; then
export CHAT_UI_URL
info "CHAT_UI_URL=${CHAT_UI_URL}"
elif [ -z "${DISPLAY:-}" ] && [ ! -e /tmp/.X11-unix ]; then
warn "CHAT_UI_URL is not set. Remote browser access will fail with"
warn "'origin not allowed' unless you set CHAT_UI_URL to the public URL"
warn "of this instance (e.g. https://openclaw0-<id>.brevlab.com)."
fi

info "Running setup.sh..."
export NVIDIA_API_KEY
exec sg docker -c "bash $SCRIPT_DIR/setup.sh"
23 changes: 22 additions & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,34 @@ cp -r "$REPO_DIR/nemoclaw-blueprint" "$BUILD_CTX/nemoclaw-blueprint"
cp -r "$REPO_DIR/scripts" "$BUILD_CTX/scripts"
rm -rf "$BUILD_CTX/nemoclaw/node_modules"

# If CHAT_UI_URL is set (e.g. by brev-setup.sh or the user), bake it into the
# Dockerfile copy so the build-time config generator writes the correct
# allowedOrigins. Without this, remote browsers hit "origin not allowed".
# Ref: https://github.com/NVIDIA/NemoClaw/issues/795
if [ -n "${CHAT_UI_URL:-}" ]; then
if [[ "$CHAT_UI_URL" =~ ^https?://[a-zA-Z0-9._:-]+(/[a-zA-Z0-9._/~%-]*)?$ ]]; then
sed -i.bak "s|^ARG CHAT_UI_URL=.*|ARG CHAT_UI_URL=${CHAT_UI_URL}|" "$BUILD_CTX/Dockerfile"
rm -f "$BUILD_CTX/Dockerfile.bak"
info "CHAT_UI_URL baked into build: ${CHAT_UI_URL}"
else
warn "CHAT_UI_URL contains invalid characters — using default (localhost)"
fi
fi

# Build the optional runtime env args (CHAT_UI_URL for nemoclaw-start.sh display).
CHAT_UI_ENV=""
if [ -n "${CHAT_UI_URL:-}" ]; then
CHAT_UI_ENV="CHAT_UI_URL=$CHAT_UI_URL"
fi

# Capture full output to a temp file so we can filter for display but still
# detect failures. The raw log is kept on failure for debugging.
CREATE_LOG=$(mktemp /tmp/nemoclaw-create-XXXXXX.log)
set +e
# shellcheck disable=SC2086 # intentional word-split on CHAT_UI_ENV (validated URL, no spaces)
openshell sandbox create --from "$BUILD_CTX/Dockerfile" --name "$SANDBOX_NAME" \
--provider nvidia-nim \
-- env NVIDIA_API_KEY="$NVIDIA_API_KEY" >"$CREATE_LOG" 2>&1
-- env NVIDIA_API_KEY="$NVIDIA_API_KEY" $CHAT_UI_ENV >"$CREATE_LOG" 2>&1
CREATE_RC=$?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word-splitting approach works but requires a shellcheck suppression and is fragile if the regex ever allows spaces. Consider using a bash array instead — more idiomatic and avoids the suppression entirely:

Suggested change
CHAT_UI_ENV=""
if [ -n "${CHAT_UI_URL:-}" ]; then
CHAT_UI_ENV="CHAT_UI_URL=$CHAT_UI_URL"
fi
# Capture full output to a temp file so we can filter for display but still
# detect failures. The raw log is kept on failure for debugging.
CREATE_LOG=$(mktemp /tmp/nemoclaw-create-XXXXXX.log)
set +e
# shellcheck disable=SC2086 # intentional word-split on CHAT_UI_ENV (validated URL, no spaces)
openshell sandbox create --from "$BUILD_CTX/Dockerfile" --name "$SANDBOX_NAME" \
--provider nvidia-nim \
-- env NVIDIA_API_KEY="$NVIDIA_API_KEY" >"$CREATE_LOG" 2>&1
-- env NVIDIA_API_KEY="$NVIDIA_API_KEY" $CHAT_UI_ENV >"$CREATE_LOG" 2>&1
CREATE_RC=$?
# Build the runtime env args array.
ENV_ARGS=(NVIDIA_API_KEY="$NVIDIA_API_KEY")
if [ -n "${CHAT_UI_URL:-}" ]; then
ENV_ARGS+=(CHAT_UI_URL="$CHAT_UI_URL")
fi
# Capture full output to a temp file so we can filter for display but still
# detect failures. The raw log is kept on failure for debugging.
CREATE_LOG=$(mktemp /tmp/nemoclaw-create-XXXXXX.log)
set +e
openshell sandbox create --from "$BUILD_CTX/Dockerfile" --name "$SANDBOX_NAME" \
--provider nvidia-nim \
-- env "${ENV_ARGS[@]}" >"$CREATE_LOG" 2>&1

set -e
rm -rf "$BUILD_CTX"
Expand Down
Loading