Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

120 changes: 85 additions & 35 deletions crates/openshell-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ struct Cli {
}

#[derive(Subcommand, Debug)]
#[allow(clippy::large_enum_variant)]
enum Commands {
// ===================================================================
// SANDBOX COMMANDS
Expand Down Expand Up @@ -1537,6 +1538,10 @@ enum SandboxCommands {
#[arg(long, value_hint = ValueHint::FilePath)]
policy: Option<String>,

/// Freeze the effective policy after initialization for this sandbox's lifetime.
#[arg(long)]
frozen: bool,

/// Forward a local port to the sandbox before the initial command or shell starts.
/// Accepts [`bind_address`:]port (e.g. 8080, 0.0.0.0:8080). Keeps the sandbox alive.
#[arg(long, conflicts_with = "no_keep")]
Expand Down Expand Up @@ -3409,6 +3414,7 @@ async fn run_async() -> Result<()> {
driver_config_json,
providers,
policy,
frozen,
forward,
expose,
expose_authorization_mode,
Expand Down Expand Up @@ -3481,41 +3487,53 @@ async fn run_async() -> Result<()> {
let endpoint = &ctx.endpoint;
let mut tls = tls.with_gateway_name(&ctx.name);
apply_auth(&mut tls, &ctx.name)?;
let exit_code = Box::pin(run::sandbox_create(
endpoint,
&ctx.name,
run::SandboxCreateConfig {
name: name.as_deref(),
template: template.as_deref(),
from: from.as_deref(),
uploads: &upload_specs,
keep,
gpu_requirements,
cpu: cpu.as_deref(),
memory: memory.as_deref(),
driver_config_json: driver_config_json.as_deref(),
editor,
providers: &providers,
policy: policy.as_deref(),
forward,
expose,
expose_authorization_mode: expose_authorization_mode.into(),
command: &command,
tty_override,
auto_providers_override,
labels: labels_map,
annotations: annotations_map,
environment: env_map,
approval_mode: &approval_mode,
output: output.as_str(),
detach,
suppress_credential_warnings: no_credential_warnings,
restart_policy: &restart_policy,
},
&cli.workspace,
&tls,
))
.await?;
let config = run::SandboxCreateConfig {
name: name.as_deref(),
template: template.as_deref(),
from: from.as_deref(),
uploads: &upload_specs,
keep,
gpu_requirements,
cpu: cpu.as_deref(),
memory: memory.as_deref(),
driver_config_json: driver_config_json.as_deref(),
editor,
providers: &providers,
policy: policy.as_deref(),
forward,
expose,
expose_authorization_mode: expose_authorization_mode.into(),
command: &command,
tty_override,
auto_providers_override,
labels: labels_map,
annotations: annotations_map,
environment: env_map,
approval_mode: &approval_mode,
output: output.as_str(),
detach,
suppress_credential_warnings: no_credential_warnings,
restart_policy: &restart_policy,
};
let exit_code = if frozen {
Box::pin(run::sandbox_create_frozen(
endpoint,
&ctx.name,
config,
&cli.workspace,
&tls,
))
.await?
} else {
Box::pin(run::sandbox_create(
endpoint,
&ctx.name,
config,
&cli.workspace,
&tls,
))
.await?
};
if exit_code != 0 {
std::process::exit(exit_code);
}
Expand Down Expand Up @@ -6342,6 +6360,38 @@ mod tests {
}
}

#[test]
fn sandbox_create_frozen_supports_inline_and_named_templates() {
for args in [
vec!["openshell", "sandbox", "create", "--frozen"],
vec![
"openshell",
"sandbox",
"create",
"--template",
"agent",
"--frozen",
],
] {
let cli = Cli::try_parse_from(args).unwrap();
assert!(matches!(
cli.command,
Some(Commands::Sandbox {
command: Some(SandboxCommands::Create { frozen: true, .. }),
..
})
));
}
let cli = Cli::try_parse_from(["openshell", "sandbox", "create"]).unwrap();
assert!(matches!(
cli.command,
Some(Commands::Sandbox {
command: Some(SandboxCommands::Create { frozen: false, .. }),
..
})
));
}

#[test]
fn sandbox_create_restart_policy_defaults_to_never() {
let cli = Cli::try_parse_from(["openshell", "sandbox", "create"]).unwrap();
Expand Down
Loading
Loading