pub struct Sandbox {
pub id: String,
pub name: String,
pub commands: Commands,
pub files: Files,
/* private fields */
}Expand description
A handle to one sandbox. Cloning is cheap; clones refer to the same sandbox. The sandbox runs one command at a time: concurrent calls queue in the plane.
Deleting is explicit: call Sandbox::kill, or use Sandbox::with, which deletes the
sandbox when its closure returns. Dropping a Sandbox leaves the sandbox running (it parks
when idle and is discarded after 5 days).
Fields§
§id: StringThe short ID (8 hex characters), usable with Sandbox::connect.
name: StringThe full resource name (instances/<org>/sessions/<id>).
commands: CommandsRuns commands in the sandbox.
files: FilesReads and writes the sandbox’s filesystem.
Implementations§
Source§impl Sandbox
impl Sandbox
Sourcepub async fn create(o: CreateOptions) -> Result<Sandbox>
pub async fn create(o: CreateOptions) -> Result<Sandbox>
Starts a new sandbox and returns when it can run commands (about 8–20 seconds). On failure it deletes anything it created. A session the plane places on a host that never starts is deleted and recreated (up to three attempts).
Sourcepub async fn with<T, F>(o: CreateOptions, f: F) -> Result<T>
pub async fn with<T, F>(o: CreateOptions, f: F) -> Result<T>
Creates a sandbox, runs f with it, and deletes the sandbox afterwards, whether f
succeeds or fails. If the returned future is dropped early or f panics, the delete is
started in the background instead.
use chainguard_sandbox::{CreateOptions, Sandbox};
let out = Sandbox::with(CreateOptions::default(), async |sbx| {
Ok(sbx.commands.run("echo hi").await?.stdout)
})
.await?;Sourcepub async fn connect(id: &str, o: ConnectOptions) -> Result<Sandbox>
pub async fn connect(id: &str, o: ConnectOptions) -> Result<Sandbox>
Returns a handle to an existing sandbox by short ID, display name or resource name. A paused sandbox resumes on its first command.
Sourcepub async fn kill(&self) -> Result<bool>
pub async fn kill(&self) -> Result<bool>
Deletes the sandbox and everything in it, and returns once it is gone, so the session slot
is free for a new sandbox. Returns false if the sandbox was already gone. If it still
exists 30 seconds after the delete request (or its disappearance can’t be confirmed), the
error is Error::Timeout with op “kill”: the deletion was requested but the slot may not
be free yet.
Sourcepub async fn pause(&self) -> Result<()>
pub async fn pause(&self) -> Result<()>
Snapshots the sandbox (memory and disk) and stops it. Running processes, including background commands, resume where they were on the next command or file operation.
Sourcepub async fn keep_alive(&self, d: Duration) -> Result<()>
pub async fn keep_alive(&self, d: Duration) -> Result<()>
Asks the plane to hold the sandbox running (not park it when idle) for d. An idle
sandbox parks after about 10 minutes, and a parked one is discarded after 5 days.
Sourcepub async fn is_running(&self) -> Result<bool>
pub async fn is_running(&self) -> Result<bool>
Whether the sandbox is running (not paused, stopped or still starting).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sandbox
impl !RefUnwindSafe for Sandbox
impl Send for Sandbox
impl Sync for Sandbox
impl Unpin for Sandbox
impl UnsafeUnpin for Sandbox
impl !UnwindSafe for Sandbox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].