@@ -105,7 +105,17 @@ async function deploy(instanceName) {
105105 if ( isRepoPrivate ( "NVIDIA/OpenShell" ) ) {
106106 await ensureGithubToken ( ) ;
107107 }
108- const name = instanceName ;
108+ const name = instanceName . trim ( ) ;
109+
110+ // Validate: same RFC 1123 subdomain rules used for sandbox names — lowercase
111+ // alphanumeric and hyphens, must start and end with alphanumeric.
112+ if ( ! / ^ [ a - z 0 - 9 ] ( [ a - z 0 - 9 - ] * [ a - z 0 - 9 ] ) ? $ / . test ( name ) || name . length > 253 ) {
113+ console . error ( ` Invalid instance name: '${ name } '` ) ;
114+ console . error ( " Names must be lowercase, contain only letters, numbers, and hyphens," ) ;
115+ console . error ( " and must start and end with a letter or number (max 253 chars)." ) ;
116+ process . exit ( 1 ) ;
117+ }
118+
109119 const gpu = process . env . NEMOCLAW_GPU || "a2-highgpu-1g:nvidia-tesla-a100:1" ;
110120
111121 console . log ( "" ) ;
@@ -127,7 +137,7 @@ async function deploy(instanceName) {
127137
128138 if ( ! exists ) {
129139 console . log ( ` Creating Brev instance '${ name } ' (${ gpu } )...` ) ;
130- run ( `brev create ${ name } --gpu "${ gpu } "` ) ;
140+ run ( `brev create " ${ name } " --gpu "${ gpu } "` ) ;
131141 } else {
132142 console . log ( ` Brev instance '${ name } ' already exists.` ) ;
133143 }
@@ -137,7 +147,7 @@ async function deploy(instanceName) {
137147 console . log ( " Waiting for SSH..." ) ;
138148 for ( let i = 0 ; i < 60 ; i ++ ) {
139149 try {
140- execSync ( `ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no ${ name } 'echo ok' 2>/dev/null` , { encoding : "utf-8" , stdio : "pipe" } ) ;
150+ execSync ( `ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no " ${ name } " 'echo ok' 2>/dev/null` , { encoding : "utf-8" , stdio : "pipe" } ) ;
141151 break ;
142152 } catch {
143153 if ( i === 59 ) {
@@ -149,31 +159,35 @@ async function deploy(instanceName) {
149159 }
150160
151161 console . log ( " Syncing NemoClaw to VM..." ) ;
152- run ( `ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR ${ name } 'mkdir -p /home/ubuntu/nemoclaw'` ) ;
153- run ( `rsync -az --delete --exclude node_modules --exclude .git --exclude src -e "ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR" "${ ROOT } /scripts" "${ ROOT } /Dockerfile" "${ ROOT } /nemoclaw" "${ ROOT } /nemoclaw-blueprint" "${ ROOT } /bin" "${ ROOT } /package.json" ${ name } :/home/ubuntu/nemoclaw/` ) ;
162+ run ( `ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR " ${ name } " 'mkdir -p /home/ubuntu/nemoclaw'` ) ;
163+ run ( `rsync -az --delete --exclude node_modules --exclude .git --exclude src -e "ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR" "${ ROOT } /scripts" "${ ROOT } /Dockerfile" "${ ROOT } /nemoclaw" "${ ROOT } /nemoclaw-blueprint" "${ ROOT } /bin" "${ ROOT } /package.json" " ${ name } " :/home/ubuntu/nemoclaw/` ) ;
154164
155165 const envLines = [ `NVIDIA_API_KEY=${ process . env . NVIDIA_API_KEY } ` ] ;
156166 const ghToken = process . env . GITHUB_TOKEN ;
157167 if ( ghToken ) envLines . push ( `GITHUB_TOKEN=${ ghToken } ` ) ;
158168 const tgToken = getCredential ( "TELEGRAM_BOT_TOKEN" ) ;
159169 if ( tgToken ) envLines . push ( `TELEGRAM_BOT_TOKEN=${ tgToken } ` ) ;
160- const envTmp = path . join ( os . tmpdir ( ) , `nemoclaw-env-${ Date . now ( ) } ` ) ;
161- fs . writeFileSync ( envTmp , envLines . join ( "\n" ) + "\n" , { mode : 0o600 } ) ;
162- run ( `scp -q -o StrictHostKeyChecking=no -o LogLevel=ERROR "${ envTmp } " ${ name } :/home/ubuntu/nemoclaw/.env` ) ;
163- fs . unlinkSync ( envTmp ) ;
170+ const envDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "nemoclaw-env-" ) ) ;
171+ const envTmp = path . join ( envDir , ".env" ) ;
172+ try {
173+ fs . writeFileSync ( envTmp , envLines . join ( "\n" ) + "\n" , { mode : 0o600 , flag : "wx" } ) ;
174+ run ( `scp -q -o StrictHostKeyChecking=no -o LogLevel=ERROR "${ envTmp } " "${ name } ":/home/ubuntu/nemoclaw/.env` ) ;
175+ } finally {
176+ fs . rmSync ( envDir , { recursive : true , force : true } ) ;
177+ }
164178
165179 console . log ( " Running setup..." ) ;
166- runInteractive ( `ssh -t -o StrictHostKeyChecking=no -o LogLevel=ERROR ${ name } 'cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && bash scripts/brev-setup.sh'` ) ;
180+ runInteractive ( `ssh -t -o StrictHostKeyChecking=no -o LogLevel=ERROR " ${ name } " 'cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && bash scripts/brev-setup.sh'` ) ;
167181
168182 if ( tgToken ) {
169183 console . log ( " Starting services..." ) ;
170- run ( `ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR ${ name } 'cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && bash scripts/start-services.sh'` ) ;
184+ run ( `ssh -o StrictHostKeyChecking=no -o LogLevel=ERROR " ${ name } " 'cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && bash scripts/start-services.sh'` ) ;
171185 }
172186
173187 console . log ( "" ) ;
174188 console . log ( " Connecting to sandbox..." ) ;
175189 console . log ( "" ) ;
176- runInteractive ( `ssh -t -o StrictHostKeyChecking=no -o LogLevel=ERROR ${ name } 'cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && openshell sandbox connect nemoclaw'` ) ;
190+ runInteractive ( `ssh -t -o StrictHostKeyChecking=no -o LogLevel=ERROR " ${ name } " 'cd /home/ubuntu/nemoclaw && set -a && . .env && set +a && openshell sandbox connect nemoclaw'` ) ;
177191}
178192
179193async function start ( ) {
0 commit comments