33---
44title: Devbox From Blueprint (Run Command, Shutdown)
55slug: devbox-from-blueprint-lifecycle
6- use_case: Create a devbox from a blueprint, run a command, validate output, and cleanly tear everything down.
6+ use_case: Create a devbox from a blueprint, run a command, fetch logs, validate output, and cleanly tear everything down.
77workflow:
88 - Create a blueprint
9+ - Fetch blueprint build logs
910 - Create a devbox from the blueprint
1011 - Execute a command in the devbox
11- - Validate exit code and stdout
12+ - Fetch devbox logs
13+ - Validate exit code, stdout, and logs
1214 - Shutdown devbox and delete blueprint
1315tags:
1416 - devbox
1517 - blueprint
1618 - commands
19+ - logs
1720 - cleanup
1821prerequisites:
1922 - RUNLOOP_API_KEY
3437
3538
3639def recipe (ctx : RecipeContext ) -> RecipeOutput :
37- """Create a devbox from a blueprint, run a command, and clean up."""
40+ """Create a devbox from a blueprint, run a command, fetch logs, and clean up."""
3841 cleanup = ctx .cleanup
3942
4043 sdk = RunloopSDK ()
@@ -46,6 +49,9 @@ def recipe(ctx: RecipeContext) -> RecipeOutput:
4649 )
4750 cleanup .add (f"blueprint:{ blueprint .id } " , blueprint .delete )
4851
52+ # Fetch blueprint build logs
53+ blueprint_logs = blueprint .logs ()
54+
4955 devbox = blueprint .create_devbox (
5056 name = unique_name ("example-devbox" ),
5157 launch_parameters = {
@@ -58,6 +64,9 @@ def recipe(ctx: RecipeContext) -> RecipeOutput:
5864 result = devbox .cmd .exec ('echo "Hello from your devbox"' )
5965 stdout = result .stdout ()
6066
67+ # Fetch devbox logs
68+ devbox_logs = devbox .logs ()
69+
6170 return RecipeOutput (
6271 resources_created = [f"blueprint:{ blueprint .id } " , f"devbox:{ devbox .id } " ],
6372 checks = [
@@ -71,6 +80,16 @@ def recipe(ctx: RecipeContext) -> RecipeOutput:
7180 passed = "Hello from your devbox" in stdout ,
7281 details = stdout .strip (),
7382 ),
83+ ExampleCheck (
84+ name = "blueprint build logs are retrievable" ,
85+ passed = blueprint_logs is not None and hasattr (blueprint_logs , "logs" ),
86+ details = f"blueprint_log_count={ len (blueprint_logs .logs )} " ,
87+ ),
88+ ExampleCheck (
89+ name = "devbox logs are retrievable" ,
90+ passed = devbox_logs is not None and hasattr (devbox_logs , "logs" ),
91+ details = f"devbox_log_count={ len (devbox_logs .logs )} " ,
92+ ),
7493 ],
7594 )
7695
0 commit comments