-
Notifications
You must be signed in to change notification settings - Fork 268
feat(sandbox): add E2B-compatible secure sandbox support #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6c889d7
dd45ddd
244e2a5
30340ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ use crate::progress::TransferProgress; | |||||||||
| const API_KEY_HEADER: &str = "X-API-Key"; | ||||||||||
| const SANDBOX_ID_HEADER: &str = "x-agentenv-sandbox-id"; | ||||||||||
| const TARGET_PORT_HEADER: &str = "x-agentenv-target-port"; | ||||||||||
| const ACCESS_TOKEN_HEADER: &str = "X-Access-Token"; | ||||||||||
| const FILESYSTEM_SERVICE: &str = "filesystem.Filesystem"; | ||||||||||
| const MAX_ERROR_BODY_BYTES: usize = 64 * 1024; | ||||||||||
| pub(crate) const TRANSFER_IDLE_TIMEOUT: Duration = Duration::from_secs(60); | ||||||||||
|
|
@@ -31,7 +32,12 @@ pub struct EnvdFilesClient { | |||||||||
| } | ||||||||||
|
|
||||||||||
| impl EnvdFilesClient { | ||||||||||
| fn new(base_url: &str, api_key: &str, sandbox_id: &str) -> Result<Self> { | ||||||||||
| fn new( | ||||||||||
| base_url: &str, | ||||||||||
| api_key: &str, | ||||||||||
| sandbox_id: &str, | ||||||||||
| envd_access_token: Option<&str>, | ||||||||||
| ) -> Result<Self> { | ||||||||||
| let mut headers = HeaderMap::new(); | ||||||||||
| headers.insert( | ||||||||||
| API_KEY_HEADER, | ||||||||||
|
|
@@ -42,6 +48,12 @@ impl EnvdFilesClient { | |||||||||
| HeaderValue::from_str(sandbox_id).context("invalid sandbox ID header value")?, | ||||||||||
| ); | ||||||||||
| headers.insert(TARGET_PORT_HEADER, HeaderValue::from_static(ENVD_PORT_STR)); | ||||||||||
| if let Some(token) = envd_access_token { | ||||||||||
| let mut token = | ||||||||||
| HeaderValue::from_str(token).context("invalid envd access token header value")?; | ||||||||||
| token.set_sensitive(true); | ||||||||||
| headers.insert(ACCESS_TOKEN_HEADER, token); | ||||||||||
| } | ||||||||||
| headers.insert( | ||||||||||
| USER_AGENT, | ||||||||||
| HeaderValue::from_str(&format!("aenv/{}", env!("CARGO_PKG_VERSION"))) | ||||||||||
|
|
@@ -60,7 +72,7 @@ impl EnvdFilesClient { | |||||||||
| Ok(Self { | ||||||||||
| base_url: base_url.trim_end_matches('/').to_string(), | ||||||||||
| http: client, | ||||||||||
| transport: Transport::new(base_url, api_key, sandbox_id)?, | ||||||||||
| transport: Transport::new(base_url, api_key, sandbox_id, envd_access_token)?, | ||||||||||
| }) | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -298,7 +310,13 @@ fn format_envd_response_error(status: reqwest::StatusCode, content: &str) -> any | |||||||||
|
|
||||||||||
| impl Client { | ||||||||||
| pub fn files(&self, sandbox_id: &str) -> Result<EnvdFilesClient> { | ||||||||||
| EnvdFilesClient::new(&self.base, &self.api_key, sandbox_id) | ||||||||||
| let sandbox = self.get_sandbox(sandbox_id)?; | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [performance · medium] Suggestion:
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [performance · medium]
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||
| EnvdFilesClient::new( | ||||||||||
|
Comment on lines
+313
to
+314
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||
| &self.base, | ||||||||||
| &self.api_key, | ||||||||||
| sandbox_id, | ||||||||||
| sandbox.envd_access_token.as_deref(), | ||||||||||
| ) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,10 +51,10 @@ pub fn run(args: Args) -> Result<()> { | |||||||||
| } | ||||||||||
|
|
||||||||||
| pub(crate) async fn attach(client: &Client, sandbox_id: &str) -> Result<i32> { | ||||||||||
| client.connect_sandbox(sandbox_id, DEFAULT_TIMEOUT_SECS)?; | ||||||||||
| let sandbox = client.connect_sandbox(sandbox_id, DEFAULT_TIMEOUT_SECS)?; | ||||||||||
|
|
||||||||||
| let (cols, rows) = terminal_size(); | ||||||||||
| let transport = Arc::new(client.transport(sandbox_id)?); | ||||||||||
| let transport = Arc::new(client.transport(sandbox_id, sandbox.envd_access_token.as_deref())?); | ||||||||||
| let mut last_error = None; | ||||||||||
| let mut started = None; | ||||||||||
| for shell in ["/bin/bash", "/bin/sh"] { | ||||||||||
|
|
@@ -116,10 +116,11 @@ pub(crate) async fn attach(client: &Client, sandbox_id: &str) -> Result<i32> { | |||||||||
| reconnect_rx, | ||||||||||
| reconnect_ack_tx, | ||||||||||
| ); | ||||||||||
| let resize_task = resize_loop(transport, selector, state.clone()); | ||||||||||
| let resize_task = resize_loop(transport.clone(), selector, state.clone()); | ||||||||||
| let watchdog_task = watchdog_loop( | ||||||||||
| client.clone(), | ||||||||||
| sandbox_id.to_string(), | ||||||||||
| transport, | ||||||||||
| state.clone(), | ||||||||||
| reconnect_tx, | ||||||||||
| reconnect_ack_rx, | ||||||||||
|
|
@@ -681,6 +682,7 @@ async fn resize_loop( | |||||||||
| async fn watchdog_loop( | ||||||||||
| client: Client, | ||||||||||
| sandbox_id: String, | ||||||||||
| transport: Arc<Transport>, | ||||||||||
| state: SessionState, | ||||||||||
| reconnect_tx: mpsc::UnboundedSender<()>, | ||||||||||
| mut reconnect_ack_rx: mpsc::UnboundedReceiver<()>, | ||||||||||
|
|
@@ -722,7 +724,7 @@ async fn watchdog_loop( | |||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| match envd_ready_probe(client.clone(), sandbox_id.clone()).await { | ||||||||||
| match envd_ready_probe(Arc::clone(&transport)).await { | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [performance · low] Suggestion:
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [performance · low] Suggestion:
Suggested change
|
||||||||||
| Ok(true) => { | ||||||||||
| unhealthy_since = None; | ||||||||||
| if matches!(previous_health, ProbeStatus::Unhealthy) { | ||||||||||
|
|
@@ -809,10 +811,11 @@ fn request_reconnect_once( | |||||||||
| *recovered_health = false; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| async fn envd_ready_probe(client: Client, sandbox_id: String) -> Result<bool> { | ||||||||||
| client | ||||||||||
| .envd_ready_with_timeout(&sandbox_id, RECONNECT_PROBE_TIMEOUT) | ||||||||||
| .await | ||||||||||
| async fn envd_ready_probe(transport: Arc<Transport>) -> Result<bool> { | ||||||||||
| match tokio::time::timeout(RECONNECT_PROBE_TIMEOUT, transport.ready()).await { | ||||||||||
|
Comment on lines
+814
to
+815
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||
| Ok(Ok(())) => Ok(true), | ||||||||||
| Ok(Err(_)) | Err(_) => Ok(false), | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fn should_refresh_session_keepalive(state: &SessionState, last_activity: &mut u64) -> bool { | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,7 +27,8 @@ async fn run_async(client: Client, args: Args) -> Result<i32> { | |||||||||||||||||||||||||||||
| .ok_or_else(|| anyhow::anyhow!("missing command"))?; | ||||||||||||||||||||||||||||||
| let rest: Vec<String> = cmd_iter.collect(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let transport = client.transport(&args.sandbox_id)?; | ||||||||||||||||||||||||||||||
| let sandbox = client.get_sandbox(&args.sandbox_id)?; | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [performance · medium] Suggestion:
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||
| let transport = client.transport(&args.sandbox_id, sandbox.envd_access_token.as_deref())?; | ||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [performance · medium] Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||
| let req = build_start_request(StartOpts { | ||||||||||||||||||||||||||||||
| cmd: &cmd, | ||||||||||||||||||||||||||||||
| args: rest, | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.