stackless_integrations/providers/e2b/
sandbox.rs1use std::collections::BTreeMap;
4
5use serde::Serialize;
6use stackless_stripe_projects::catalog::verify::CatalogService;
7use stackless_stripe_projects::provision::ProvisionContext;
8
9use super::FamilyResource;
10use crate::error::IntegrationError;
11use crate::hostable::{ConfigScope, Hostable, IntegrationHosting};
12
13pub const RESOURCE_KIND: &str = "integration-e2b";
14
15#[derive(Debug, Serialize)]
16pub struct E2BSandboxConfig {}
17
18impl CatalogService for E2BSandboxConfig {
19 const REFERENCE: &'static str = "e2b/sandbox";
20}
21
22#[derive(Debug)]
23pub struct E2BSandbox;
24
25impl Hostable for E2BSandbox {
26 const PROVIDER: &'static str = "e2b";
27 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
28 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
29 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
30 const OUTPUTS: &'static [&'static str] = &["api_key"];
31}
32
33impl FamilyResource for E2BSandbox {
34 type Config = E2BSandboxConfig;
35 const PROVIDER_PREFIX: &'static str = "E2B";
36 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] =
38 &[("API_KEY", "api_key", true)];
39
40 fn build_config(ctx: &ProvisionContext<'_>) -> Result<E2BSandboxConfig, IntegrationError> {
41 let _ = super::integration_config(ctx)?;
42 Ok(E2BSandboxConfig {})
43 }
44}
45
46pub fn validate_config(
47 name: &str,
48 config: &BTreeMap<String, toml::Value>,
49) -> Result<(), IntegrationError> {
50 let _ = (name, config);
51 Ok(())
52}
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57 use crate::ProviderOps;
58 use crate::resource::ResourcePayload;
59 use stackless_core::def::StackDef;
60 use stackless_stripe_projects::stripe::StripeProjects;
61 use stackless_stripe_projects::test_support;
62
63 #[test]
64 fn config_matches_catalog() {
65 const FIXTURE: &str = include_str!(concat!(
66 env!("CARGO_MANIFEST_DIR"),
67 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
68 ));
69 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
70 let failures = stackless_stripe_projects::verify_service(&catalog, &E2BSandboxConfig {});
71 assert!(
72 failures.is_empty(),
73 "e2b/sandbox catalog gaps:\n{}",
74 failures.join("\n")
75 );
76 }
77
78 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_sandbox","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_e2b","provider_name":"E2B","service_id":"sandbox","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{"type":"object","required":[],"additionalProperties":false,"properties":{}}}]}}"##;
79
80 fn test_def() -> StackDef {
81 StackDef::parse(
82 r#"
83[stack]
84name = "atto"
85[stack.projects.stripe]
86project = "project_1"
87[integrations.res]
88provider = "e2b"
89[services.api]
90source = { repo = "r", ref = "main" }
91env = { OUT = "${integrations.res.api_key}" }
92health = { path = "/health" }
93[services.api.local]
94run = "true"
95"#,
96 )
97 .unwrap()
98 }
99
100 #[tokio::test]
101 async fn provision_records_outputs() {
102 let runner = test_support::provision_script(
103 CATALOG_ENVELOPE,
104 serde_json::json!({"E2B_API_KEY": "val_api_key"}),
105 0,
106 );
107 let dir = tempfile::tempdir().unwrap();
108 std::fs::write(
109 dir.path().join("stackless.toml"),
110 "[stack]\nname=\"atto\"\n",
111 )
112 .unwrap();
113 let stripe = StripeProjects::new(&runner, dir.path());
114
115 let resource = E2BSandbox
116 .provision(
117 &stripe.as_dyn(),
118 &test_def(),
119 dir.path(),
120 "demo",
121 "res",
122 "local",
123 false,
124 )
125 .await
126 .unwrap();
127 assert_eq!(resource.resource_kind, "integration-e2b");
128 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
129 assert_eq!(payload.outputs["api_key"], "val_api_key");
130 }
131}