@@ -14,6 +14,8 @@ type CliOptions = {
1414 createTimeoutSec : number ;
1515 installTimeoutSec : number ;
1616 analyzeTimeoutSec : number ;
17+ autoStopInterval ?: number ;
18+ autoDeleteInterval ?: number ;
1719 keepSandbox : boolean ;
1820 target ?: string ;
1921 model ?: string ;
@@ -52,6 +54,32 @@ function parsePositiveInt(value: string, flag: string): number {
5254 return parsed ;
5355}
5456
57+ function parseAutoStopInterval ( value : string | undefined , source : string ) : number | undefined {
58+ if ( value === undefined ) {
59+ return undefined ;
60+ }
61+ const parsed = Number . parseInt ( value , 10 ) ;
62+ if ( ! Number . isInteger ( parsed ) || parsed < 0 ) {
63+ throw new Error (
64+ `${ source } must be a non-negative integer (0 disables auto-stop). Received "${ value } ".` ,
65+ ) ;
66+ }
67+ return parsed ;
68+ }
69+
70+ function parseAutoDeleteInterval ( value : string | undefined , source : string ) : number | undefined {
71+ if ( value === undefined ) {
72+ return undefined ;
73+ }
74+ const parsed = Number . parseInt ( value , 10 ) ;
75+ if ( ! Number . isInteger ( parsed ) || ( parsed !== - 1 && parsed <= 0 ) ) {
76+ throw new Error (
77+ `${ source } must be -1 (disable auto-delete) or a positive integer. Received "${ value } ".` ,
78+ ) ;
79+ }
80+ return parsed ;
81+ }
82+
5583function requireEnv ( name : string ) : string {
5684 const value = process . env [ name ] ;
5785 if ( ! value ) {
@@ -178,6 +206,8 @@ function parseCliOptions(): CliOptions {
178206 "create-timeout-sec" : { type : "string" , default : "180" } ,
179207 "install-timeout-sec" : { type : "string" , default : "900" } ,
180208 "analyze-timeout-sec" : { type : "string" , default : "2400" } ,
209+ "auto-stop-interval" : { type : "string" } ,
210+ "auto-delete-interval" : { type : "string" } ,
181211 "keep-sandbox" : { type : "boolean" , default : false } ,
182212 target : { type : "string" } ,
183213 model : { type : "string" } ,
@@ -203,6 +233,8 @@ Options:
203233 --create-timeout-sec <n> Sandbox creation timeout (default: 180)
204234 --install-timeout-sec <n> OpenCode install timeout (default: 900)
205235 --analyze-timeout-sec <n> Per-repo analysis timeout (default: 2400)
236+ --auto-stop-interval <n> Daytona auto-stop interval (minutes, 0 disables)
237+ --auto-delete-interval <n> Daytona auto-delete interval (minutes, -1 disables)
206238 --target <name> Daytona target override
207239 --model <provider/model> OpenCode model (default: zai-coding-plan/glm-4.7-flash)
208240 --variant <name> Model variant (example: xhigh)
@@ -213,12 +245,24 @@ Options:
213245 process . exit ( 0 ) ;
214246 }
215247
248+ const autoStopInterval =
249+ parseAutoStopInterval ( values [ "auto-stop-interval" ] , "--auto-stop-interval" ) ??
250+ parseAutoStopInterval ( process . env . DAYTONA_AUTO_STOP_INTERVAL , "DAYTONA_AUTO_STOP_INTERVAL" ) ;
251+ const autoDeleteInterval =
252+ parseAutoDeleteInterval ( values [ "auto-delete-interval" ] , "--auto-delete-interval" ) ??
253+ parseAutoDeleteInterval (
254+ process . env . DAYTONA_AUTO_DELETE_INTERVAL ,
255+ "DAYTONA_AUTO_DELETE_INTERVAL" ,
256+ ) ;
257+
216258 return {
217259 inputFile : values . input ,
218260 outDir : values [ "out-dir" ] ,
219261 createTimeoutSec : parsePositiveInt ( values [ "create-timeout-sec" ] , "--create-timeout-sec" ) ,
220262 installTimeoutSec : parsePositiveInt ( values [ "install-timeout-sec" ] , "--install-timeout-sec" ) ,
221263 analyzeTimeoutSec : parsePositiveInt ( values [ "analyze-timeout-sec" ] , "--analyze-timeout-sec" ) ,
264+ autoStopInterval,
265+ autoDeleteInterval,
222266 keepSandbox : values [ "keep-sandbox" ] ,
223267 target : values . target ,
224268 model : values . model ,
@@ -615,14 +659,25 @@ async function analyzeOneRepo(params: {
615659 const sandboxName = sanitizeSlug (
616660 `audit-${ slug } -${ Date . now ( ) . toString ( 36 ) } ${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 6 ) } ` ,
617661 ) . slice ( 0 , 63 ) ;
618- sandbox = await daytona . create (
619- {
620- name : sandboxName ,
621- language : "typescript" ,
622- autoStopInterval : 0 ,
623- } ,
624- { timeout : options . createTimeoutSec } ,
625- ) ;
662+
663+ const createParams : {
664+ name : string ;
665+ language : "typescript" ;
666+ autoStopInterval ?: number ;
667+ autoDeleteInterval ?: number ;
668+ } = {
669+ name : sandboxName ,
670+ language : "typescript" ,
671+ } ;
672+
673+ if ( options . autoStopInterval !== undefined ) {
674+ createParams . autoStopInterval = options . autoStopInterval ;
675+ }
676+ if ( options . autoDeleteInterval !== undefined ) {
677+ createParams . autoDeleteInterval = options . autoDeleteInterval ;
678+ }
679+
680+ sandbox = await daytona . create ( createParams , { timeout : options . createTimeoutSec } ) ;
626681 console . log ( `[analyze] (${ runPrefix } ) Sandbox ready: ${ sandbox . id } ` ) ;
627682
628683 const userHome = ( await sandbox . getUserHomeDir ( ) ) ?? "/home/daytona" ;
0 commit comments