pub trait CodeExecutor: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn capabilities(&self) -> BackendCapabilities;
fn supports_language(&self, lang: &ExecutionLanguage) -> bool;
fn execute<'life0, 'async_trait>(
&'life0 self,
request: ExecutionRequest,
) -> Pin<Box<dyn Future<Output = Result<ExecutionResult, ExecutionError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
// Provided methods
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn restart<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn is_running<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait { ... }
fn prompt_snippet(&self) -> Option<String> { ... }
}code only.Expand description
Async trait for code execution backends.
Backends may optionally implement lifecycle methods (start,
stop, restart) for persistent execution
environments like containers. The default implementations are no-ops, so
simple backends (e.g., host-local rustc) work without lifecycle management.
Backends that support persistent environments should override these methods
and report supports_persistent_workspace: true in their capabilities.
Required Methods§
Sourcefn capabilities(&self) -> BackendCapabilities
fn capabilities(&self) -> BackendCapabilities
The capabilities this backend can enforce.
Sourcefn supports_language(&self, lang: &ExecutionLanguage) -> bool
fn supports_language(&self, lang: &ExecutionLanguage) -> bool
Whether this backend supports the given language.
Sourcefn execute<'life0, 'async_trait>(
&'life0 self,
request: ExecutionRequest,
) -> Pin<Box<dyn Future<Output = Result<ExecutionResult, ExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
request: ExecutionRequest,
) -> Pin<Box<dyn Future<Output = Result<ExecutionResult, ExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Execute a request and return a structured result.
Provided Methods§
Sourcefn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Start the execution environment (e.g., create and start a container).
For persistent backends, this creates the underlying environment and
makes it ready for execute calls. Calling execute
on a started backend reuses the same environment.
The default implementation is a no-op for backends that don’t need lifecycle management (e.g., host-local compilation).
Sourcefn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Stop the execution environment and release resources.
For persistent backends, this stops and removes the underlying
environment (e.g., stops and removes a Docker container). After
stop, the backend can be restarted with start.
The default implementation is a no-op.
Sourcefn restart<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn restart<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Sourcefn is_running<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn is_running<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Sourcefn prompt_snippet(&self) -> Option<String>
fn prompt_snippet(&self) -> Option<String>
A prose snippet describing this backend’s execution environment and built-in capabilities, suitable for appending to an LLM-facing tool description.
None (the default) means the backend has nothing to add. Backends
whose behavior depends on construction-time configuration (granted
filesystem roots, environment variables, registered host functions,
state persistence semantics) should override this so tools composed
over Arc<dyn CodeExecutor> can surface an accurate environment
description to the model without downcasting.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".