Skip to content
Closed
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
23 changes: 20 additions & 3 deletions nemoclaw-blueprint/orchestrator/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import argparse
import json
import os
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -72,6 +73,17 @@ def openshell_available() -> bool:
return shutil.which("openshell") is not None


def normalize_sandbox_name(name: str) -> str:
"""Normalize sandbox name to lowercase and validate it."""
normalized = name.lower()
# Only lowercase letters, numbers, and hyphens allowed
if not re.match(r'^[a-z0-9-]+$', normalized):
raise ValueError(f"Invalid sandbox name: '{name}'. Only lowercase letters, numbers, and hyphens are allowed.")
if len(normalized) > 64:
raise ValueError(f"Sandbox name too long: '{name}'. Must be 64 characters or less.")
return normalized
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved


# ---------------------------------------------------------------------------
# Actions
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -109,12 +121,15 @@ def action_plan(
if endpoint_url:
inference_cfg = {**inference_cfg, "endpoint": endpoint_url}

# Normalize sandbox name to lowercase
sandbox_name = normalize_sandbox_name(sandbox_cfg.get("name", "openclaw"))

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
plan: dict[str, Any] = {
"run_id": rid,
"profile": profile,
"sandbox": {
"image": sandbox_cfg.get("image", "openclaw"),
"name": sandbox_cfg.get("name", "openclaw"),
"name": sandbox_name,
"forward_ports": sandbox_cfg.get("forward_ports", [18789]),
},
"inference": {
Expand Down Expand Up @@ -160,7 +175,8 @@ def action_apply(

sandbox_cfg: dict[str, Any] = blueprint.get("components", {}).get("sandbox", {})

sandbox_name: str = sandbox_cfg.get("name", "openclaw")
# Normalize sandbox name to lowercase
sandbox_name: str = normalize_sandbox_name(sandbox_cfg.get("name", "openclaw"))
sandbox_image: str = sandbox_cfg.get("image", "openclaw")
forward_ports: list[int] = sandbox_cfg.get("forward_ports", [18789])

Expand Down Expand Up @@ -282,7 +298,8 @@ def action_rollback(rid: str) -> None:
plan_file = state_dir / "plan.json"
if plan_file.exists():
plan = json.loads(plan_file.read_text())
sandbox_name = plan.get("sandbox_name", "openclaw")
# Normalize sandbox name from plan (in case it was saved before normalization)
sandbox_name = normalize_sandbox_name(plan.get("sandbox_name", "openclaw"))

progress(30, f"Stopping sandbox {sandbox_name}")
run_cmd(
Expand Down
2 changes: 1 addition & 1 deletion nemoclaw/dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions nemoclaw/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nemoclaw/dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 24 additions & 4 deletions nemoclaw/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ const DEFAULT_PLUGIN_CONFIG: NemoClawConfig = {
inferenceProvider: "nvidia",
};

/**
* Normalizes a sandbox name to lowercase and validates it.
* Returns the normalized name or the default if invalid.
*/
function normalizeSandboxName(name: string | unknown, defaultName: string): string {
if (typeof name !== "string" || !name) {
return defaultName;
}
// Normalize to lowercase
const normalized = name.toLowerCase();
// Validate: only lowercase letters, numbers, and hyphens allowed
if (!/^[a-z0-9-]+$/.test(normalized)) {
return defaultName;
}
if (normalized.length > 64) {
return defaultName;
}
return normalized;
}

export function getPluginConfig(api: OpenClawPluginApi): NemoClawConfig {
const raw = api.pluginConfig ?? {};
return {
Expand All @@ -224,10 +244,10 @@ export function getPluginConfig(api: OpenClawPluginApi): NemoClawConfig {
typeof raw["blueprintRegistry"] === "string"
? raw["blueprintRegistry"]
: DEFAULT_PLUGIN_CONFIG.blueprintRegistry,
sandboxName:
typeof raw["sandboxName"] === "string"
? raw["sandboxName"]
: DEFAULT_PLUGIN_CONFIG.sandboxName,
sandboxName: normalizeSandboxName(
raw["sandboxName"],
DEFAULT_PLUGIN_CONFIG.sandboxName,
),
inferenceProvider:
typeof raw["inferenceProvider"] === "string"
? raw["inferenceProvider"]
Expand Down
Loading