@@ -306,6 +306,25 @@ function getCurlTimingArgs() {
306306 return [ "--connect-timeout 5" , "--max-time 20" ] ;
307307}
308308
309+ function getSandboxCreateSanitizedEnv ( baseEnv = process . env ) {
310+ const env = { ...baseEnv } ;
311+ const strippedNames = new Set ( [
312+ ...Object . values ( REMOTE_PROVIDER_CONFIG ) . map ( ( config ) => config . credentialEnv ) . filter ( Boolean ) ,
313+ "DISCORD_BOT_TOKEN" ,
314+ "SLACK_BOT_TOKEN" ,
315+ "TELEGRAM_BOT_TOKEN" ,
316+ ] ) ;
317+ for ( const name of strippedNames ) {
318+ delete env [ name ] ;
319+ }
320+ return env ;
321+ }
322+
323+ function resolveCredentialValue ( credentialEnv ) {
324+ if ( ! credentialEnv ) return "" ;
325+ return process . env [ credentialEnv ] || getCredential ( credentialEnv ) || "" ;
326+ }
327+
309328function buildProviderArgs ( action , name , type , credentialEnv , baseUrl ) {
310329 const args =
311330 action === "create"
@@ -619,7 +638,7 @@ async function validateOpenAiLikeSelection(
619638 credentialEnv = null ,
620639 retryMessage = "Please choose a provider/model again."
621640) {
622- const apiKey = credentialEnv ? getCredential ( credentialEnv ) : "" ;
641+ const apiKey = resolveCredentialValue ( credentialEnv ) ;
623642 const probe = probeOpenAiLikeEndpoint ( endpointUrl , model , apiKey ) ;
624643 if ( ! probe . ok ) {
625644 console . error ( ` ${ label } endpoint validation failed.` ) ;
@@ -635,31 +654,14 @@ async function validateOpenAiLikeSelection(
635654 return probe . api ;
636655}
637656
638- async function validateAnthropicSelection ( label , endpointUrl , model , credentialEnv ) {
639- const apiKey = getCredential ( credentialEnv ) ;
640- const probe = probeAnthropicEndpoint ( endpointUrl , model , apiKey ) ;
641- if ( ! probe . ok ) {
642- console . error ( ` ${ label } endpoint validation failed.` ) ;
643- console . error ( ` ${ probe . message } ` ) ;
644- if ( isNonInteractive ( ) ) {
645- process . exit ( 1 ) ;
646- }
647- console . log ( " Please choose a provider/model again." ) ;
648- console . log ( "" ) ;
649- return null ;
650- }
651- console . log ( ` ${ probe . label } available — OpenClaw will use ${ probe . api } .` ) ;
652- return probe . api ;
653- }
654-
655- async function validateAnthropicSelectionWithRetryMessage (
657+ async function validateAnthropicSelection (
656658 label ,
657659 endpointUrl ,
658660 model ,
659661 credentialEnv ,
660662 retryMessage = "Please choose a provider/model again."
661663) {
662- const apiKey = getCredential ( credentialEnv ) ;
664+ const apiKey = resolveCredentialValue ( credentialEnv ) ;
663665 const probe = probeAnthropicEndpoint ( endpointUrl , model , apiKey ) ;
664666 if ( ! probe . ok ) {
665667 console . error ( ` ${ label } endpoint validation failed.` ) ;
@@ -676,7 +678,7 @@ async function validateAnthropicSelectionWithRetryMessage(
676678}
677679
678680async function validateCustomOpenAiLikeSelection ( label , endpointUrl , model , credentialEnv ) {
679- const apiKey = getCredential ( credentialEnv ) ;
681+ const apiKey = resolveCredentialValue ( credentialEnv ) ;
680682 const probe = probeOpenAiLikeEndpoint ( endpointUrl , model , apiKey ) ;
681683 if ( probe . ok ) {
682684 console . log ( ` ${ probe . label } available — OpenClaw will use ${ probe . api } .` ) ;
@@ -698,7 +700,7 @@ async function validateCustomOpenAiLikeSelection(label, endpointUrl, model, cred
698700}
699701
700702async function validateCustomAnthropicSelection ( label , endpointUrl , model , credentialEnv ) {
701- const apiKey = getCredential ( credentialEnv ) ;
703+ const apiKey = resolveCredentialValue ( credentialEnv ) ;
702704 const probe = probeAnthropicEndpoint ( endpointUrl , model , apiKey ) ;
703705 if ( probe . ok ) {
704706 console . log ( ` ${ probe . label } available — OpenClaw will use ${ probe . api } .` ) ;
@@ -1387,18 +1389,7 @@ async function createSandbox(gpu, model, provider, preferredInferenceApi = null)
13871389 const chatUiUrl = process . env . CHAT_UI_URL || "http://127.0.0.1:18789" ;
13881390 patchStagedDockerfile ( stagedDockerfile , model , chatUiUrl , String ( Date . now ( ) ) , provider , preferredInferenceApi ) ;
13891391 const envArgs = [ formatEnvAssignment ( "CHAT_UI_URL" , chatUiUrl ) ] ;
1390- const sandboxEnv = { ...process . env } ;
1391- if ( process . env . NVIDIA_API_KEY ) {
1392- sandboxEnv . NVIDIA_API_KEY = process . env . NVIDIA_API_KEY ;
1393- }
1394- const discordToken = getCredential ( "DISCORD_BOT_TOKEN" ) || process . env . DISCORD_BOT_TOKEN ;
1395- if ( discordToken ) {
1396- sandboxEnv . DISCORD_BOT_TOKEN = discordToken ;
1397- }
1398- const slackToken = getCredential ( "SLACK_BOT_TOKEN" ) || process . env . SLACK_BOT_TOKEN ;
1399- if ( slackToken ) {
1400- sandboxEnv . SLACK_BOT_TOKEN = slackToken ;
1401- }
1392+ const sandboxEnv = getSandboxCreateSanitizedEnv ( ) ;
14021393
14031394 // Run without piping through awk — the pipe masked non-zero exit codes
14041395 // from openshell because bash returns the status of the last pipeline
@@ -1660,7 +1651,7 @@ async function setupNim(gpu) {
16601651 } else {
16611652 const retryMessage = "Please choose a provider/model again." ;
16621653 if ( selected . key === "anthropic" ) {
1663- preferredInferenceApi = await validateAnthropicSelectionWithRetryMessage (
1654+ preferredInferenceApi = await validateAnthropicSelection (
16641655 remoteConfig . label ,
16651656 endpointUrl || ANTHROPIC_ENDPOINT_URL ,
16661657 model ,
0 commit comments