@@ -504,6 +504,7 @@ struct Cli {
504504}
505505
506506#[ derive( Subcommand , Debug ) ]
507+ #[ allow( clippy:: large_enum_variant) ]
507508enum Commands {
508509 // ===================================================================
509510 // SANDBOX COMMANDS
@@ -1536,6 +1537,10 @@ enum SandboxCommands {
15361537 #[ arg( long, value_hint = ValueHint :: FilePath ) ]
15371538 policy : Option < String > ,
15381539
1540+ /// Freeze the effective policy after initialization for this sandbox's lifetime.
1541+ #[ arg( long) ]
1542+ frozen : bool ,
1543+
15391544 /// Forward a local port to the sandbox before the initial command or shell starts.
15401545 /// Accepts [`bind_address`:]port (e.g. 8080, 0.0.0.0:8080). Keeps the sandbox alive.
15411546 #[ arg( long, conflicts_with = "no_keep" ) ]
@@ -3395,6 +3400,7 @@ async fn run_async() -> Result<()> {
33953400 driver_config_json,
33963401 providers,
33973402 policy,
3403+ frozen,
33983404 forward,
33993405 expose,
34003406 expose_authorization_mode,
@@ -3467,41 +3473,53 @@ async fn run_async() -> Result<()> {
34673473 let endpoint = & ctx. endpoint ;
34683474 let mut tls = tls. with_gateway_name ( & ctx. name ) ;
34693475 apply_auth ( & mut tls, & ctx. name ) ?;
3470- let exit_code = Box :: pin ( run:: sandbox_create (
3471- endpoint,
3472- & ctx. name ,
3473- run:: SandboxCreateConfig {
3474- name : name. as_deref ( ) ,
3475- template : template. as_deref ( ) ,
3476- from : from. as_deref ( ) ,
3477- uploads : & upload_specs,
3478- keep,
3479- gpu_requirements,
3480- cpu : cpu. as_deref ( ) ,
3481- memory : memory. as_deref ( ) ,
3482- driver_config_json : driver_config_json. as_deref ( ) ,
3483- editor,
3484- providers : & providers,
3485- policy : policy. as_deref ( ) ,
3486- forward,
3487- expose,
3488- expose_authorization_mode : expose_authorization_mode. into ( ) ,
3489- command : & command,
3490- tty_override,
3491- auto_providers_override,
3492- labels : labels_map,
3493- annotations : annotations_map,
3494- environment : env_map,
3495- approval_mode : & approval_mode,
3496- output : output. as_str ( ) ,
3497- detach,
3498- suppress_credential_warnings : no_credential_warnings,
3499- restart_policy : & restart_policy,
3500- } ,
3501- & cli. workspace ,
3502- & tls,
3503- ) )
3504- . await ?;
3476+ let config = run:: SandboxCreateConfig {
3477+ name : name. as_deref ( ) ,
3478+ template : template. as_deref ( ) ,
3479+ from : from. as_deref ( ) ,
3480+ uploads : & upload_specs,
3481+ keep,
3482+ gpu_requirements,
3483+ cpu : cpu. as_deref ( ) ,
3484+ memory : memory. as_deref ( ) ,
3485+ driver_config_json : driver_config_json. as_deref ( ) ,
3486+ editor,
3487+ providers : & providers,
3488+ policy : policy. as_deref ( ) ,
3489+ forward,
3490+ expose,
3491+ expose_authorization_mode : expose_authorization_mode. into ( ) ,
3492+ command : & command,
3493+ tty_override,
3494+ auto_providers_override,
3495+ labels : labels_map,
3496+ annotations : annotations_map,
3497+ environment : env_map,
3498+ approval_mode : & approval_mode,
3499+ output : output. as_str ( ) ,
3500+ detach,
3501+ suppress_credential_warnings : no_credential_warnings,
3502+ restart_policy : & restart_policy,
3503+ } ;
3504+ let exit_code = if frozen {
3505+ Box :: pin ( run:: sandbox_create_frozen (
3506+ endpoint,
3507+ & ctx. name ,
3508+ config,
3509+ & cli. workspace ,
3510+ & tls,
3511+ ) )
3512+ . await ?
3513+ } else {
3514+ Box :: pin ( run:: sandbox_create (
3515+ endpoint,
3516+ & ctx. name ,
3517+ config,
3518+ & cli. workspace ,
3519+ & tls,
3520+ ) )
3521+ . await ?
3522+ } ;
35053523 if exit_code != 0 {
35063524 std:: process:: exit ( exit_code) ;
35073525 }
@@ -6324,6 +6342,38 @@ mod tests {
63246342 }
63256343 }
63266344
6345+ #[ test]
6346+ fn sandbox_create_frozen_supports_inline_and_named_templates ( ) {
6347+ for args in [
6348+ vec ! [ "openshell" , "sandbox" , "create" , "--frozen" ] ,
6349+ vec ! [
6350+ "openshell" ,
6351+ "sandbox" ,
6352+ "create" ,
6353+ "--template" ,
6354+ "agent" ,
6355+ "--frozen" ,
6356+ ] ,
6357+ ] {
6358+ let cli = Cli :: try_parse_from ( args) . unwrap ( ) ;
6359+ assert ! ( matches!(
6360+ cli. command,
6361+ Some ( Commands :: Sandbox {
6362+ command: Some ( SandboxCommands :: Create { frozen: true , .. } ) ,
6363+ ..
6364+ } )
6365+ ) ) ;
6366+ }
6367+ let cli = Cli :: try_parse_from ( [ "openshell" , "sandbox" , "create" ] ) . unwrap ( ) ;
6368+ assert ! ( matches!(
6369+ cli. command,
6370+ Some ( Commands :: Sandbox {
6371+ command: Some ( SandboxCommands :: Create { frozen: false , .. } ) ,
6372+ ..
6373+ } )
6374+ ) ) ;
6375+ }
6376+
63276377 #[ test]
63286378 fn sandbox_create_restart_policy_defaults_to_never ( ) {
63296379 let cli = Cli :: try_parse_from ( [ "openshell" , "sandbox" , "create" ] ) . unwrap ( ) ;
0 commit comments