From cc58205905838b2e61a587d51bd23706ac4e104a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 03:36:09 +0000 Subject: [PATCH 1/2] feat(sandboxes): floo sandboxes create --keep-warm Seconds its machine stays attached after the last command, 0 to 86400, refused before the API is asked when out of range. Sent only when given, so an API from before the field still takes a plain create. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Eufw49FxjEvjnPwH2t3M4n --- src/cli.rs | 18 ++++++++++++++++++ src/commands/sandboxes.rs | 7 ++++++- tests/sandboxes_tests.rs | 26 +++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 166ba05..e7a7321 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1870,6 +1870,12 @@ pub enum SandboxesCommands { #[arg(long)] name: Option, + /// Seconds its machine stays attached after the last command, 0 to 86400, + /// so the next command skips a boot. They bill as a running machine. + /// Default: floo's, 30. + #[arg(long, value_name = "SECONDS", value_parser = keep_warm_seconds)] + keep_warm: Option, + /// A tag to list it by, as name=value. Repeatable. #[arg(long = "tag", value_name = "NAME=VALUE")] tags: Vec, @@ -2137,6 +2143,16 @@ pub enum CronCommands { /// Agents and `--json` runs update too: they never run `floo update` on their /// own, so a gate on an interactive terminal left them on old releases. Update /// notices go to stderr, so stdout and `--json` output stay clean. +/// `--keep-warm`: seconds, 0 to a day, as the API takes them. +fn keep_warm_seconds(given: &str) -> Result { + match given.parse::() { + Ok(seconds) if (0.0..=86400.0).contains(&seconds) => Ok(seconds), + _ => Err(format!( + "must be a number of seconds, 0 to 86400, got: {given}" + )), + } +} + fn should_check_version(cli: &Cli) -> bool { if crate::config::is_local_binary() || crate::config::is_dev_binary() { return false; @@ -2904,6 +2920,7 @@ pub fn run() { timeout, env, name, + keep_warm, tags, } => commands::sandboxes::create(&commands::sandboxes::CreateArgs { app: &app, @@ -2912,6 +2929,7 @@ pub fn run() { timeout, env: &env, name: name.as_deref(), + keep_warm, tags: &tags, }), SandboxesCommands::Exec { diff --git a/src/commands/sandboxes.rs b/src/commands/sandboxes.rs index 9aca6c2..55deddf 100644 --- a/src/commands/sandboxes.rs +++ b/src/commands/sandboxes.rs @@ -22,6 +22,7 @@ pub struct CreateArgs<'a> { pub timeout: u64, pub env: &'a [String], pub name: Option<&'a str>, + pub keep_warm: Option, pub tags: &'a [String], } @@ -37,7 +38,7 @@ pub fn create(args: &CreateArgs) { process::exit(1); }) }); - let body = serde_json::json!({ + let mut body = serde_json::json!({ "app": args.app, "image": image, "size": args.size, @@ -46,6 +47,10 @@ pub fn create(args: &CreateArgs) { "name": args.name, "tags": pairs(args.tags, "--tag", "task=build"), }); + if let Some(seconds) = args.keep_warm { + // Sent only when given: an API from before it refuses the field, even as null. + body["keep_warm"] = serde_json::json!(seconds); + } if !output::is_json_mode() { output::info( "Creating the sandbox. A new image's first build takes a few minutes.", diff --git a/tests/sandboxes_tests.rs b/tests/sandboxes_tests.rs index 28aa76a..225b9a4 100644 --- a/tests/sandboxes_tests.rs +++ b/tests/sandboxes_tests.rs @@ -236,7 +236,7 @@ fn create_sends_what_was_asked_and_prints_only_the_id_on_stdout() { let created = server .mock("POST", "/v1/orgs/sandboxes") .match_body(Matcher::PartialJsonString( - r#"{"app":"agents","size":"medium","timeout":900,"env":{"DEBUG":"1"},"tags":{"task":"build"}}"# + r#"{"app":"agents","size":"medium","timeout":900,"env":{"DEBUG":"1"},"tags":{"task":"build"},"keep_warm":5.0}"# .to_string(), )) .with_status(201) @@ -255,6 +255,8 @@ fn create_sends_what_was_asked_and_prints_only_the_id_on_stdout() { "DEBUG=1", "--tag", "task=build", + "--keep-warm", + "5", ]) .env("HOME", home.path()) .assert() @@ -263,6 +265,28 @@ fn create_sends_what_was_asked_and_prints_only_the_id_on_stdout() { created.assert(); } +#[test] +fn create_refuses_a_keep_warm_past_a_day_before_asking_the_api() { + let mut server = Server::new(); + let home = setup_config(&server); + let created = server.mock("POST", "/v1/orgs/sandboxes").expect(0).create(); + + floo() + .args([ + "sandboxes", + "create", + "--app", + "agents", + "--keep-warm", + "86401", + ]) + .env("HOME", home.path()) + .assert() + .failure() + .stderr(predicate::str::contains("0 to 86400")); + created.assert(); +} + #[test] fn exec_prints_each_stream_and_exits_with_the_commands_code() { let mut server = Server::new(); From b743534dbd3af781797a5776a7fb5dba23191996 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 05:05:17 +0000 Subject: [PATCH 2/2] docs(sandboxes): --keep-warm help says floo's default is 5 s Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Eufw49FxjEvjnPwH2t3M4n --- src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index d8e9e06..8182ee9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1872,7 +1872,7 @@ pub enum SandboxesCommands { /// Seconds its machine stays attached after the last command, 0 to 86400, /// so the next command skips a boot. They bill as a running machine. - /// Default: floo's, 30. + /// Default: floo's, 5. #[arg(long, value_name = "SECONDS", value_parser = keep_warm_seconds)] keep_warm: Option,