pub struct DockerConfig {
pub image: String,
pub work_dir: String,
pub setup_commands: Vec<String>,
pub environment: Vec<String>,
pub bind_mounts: Vec<String>,
pub network_disabled: bool,
pub container_name_prefix: String,
pub auto_start: bool,
pub auto_remove: bool,
}Expand description
Configuration for the Docker executor.
§Example
use adk_code::DockerConfig;
let config = DockerConfig::python();
assert_eq!(config.image, "python:3.12-slim");
assert_eq!(config.work_dir, "/workspace");Fields§
§image: StringContainer image to use.
work_dir: StringWorking directory inside the container.
setup_commands: Vec<String>Setup commands to run after container creation (e.g., pip install).
environment: Vec<String>Extra environment variables to set in the container.
bind_mounts: Vec<String>Bind mounts in host:container[:ro] format.
network_disabled: boolWhether to disable network access.
container_name_prefix: StringContainer name prefix (a random suffix is appended).
auto_start: boolWhether to auto-start on first execute if not already running.
auto_remove: boolWhether to auto-stop and remove the container on drop.
Implementations§
Source§impl DockerConfig
impl DockerConfig
Sourcepub fn setup_command(self, cmd: impl Into<String>) -> Self
pub fn setup_command(self, cmd: impl Into<String>) -> Self
Add a setup command to run after container creation.
Sourcepub fn pip_install(self, packages: &[&str]) -> Self
pub fn pip_install(self, packages: &[&str]) -> Self
Add a pip install command for Python dependencies.
Sourcepub fn npm_install(self, packages: &[&str]) -> Self
pub fn npm_install(self, packages: &[&str]) -> Self
Add an npm install command for Node.js dependencies.
Sourcepub fn with_network(self) -> Self
pub fn with_network(self) -> Self
Enable network access (disabled by default).
Sourcepub fn bind_mount(self, mount: impl Into<String>) -> Self
pub fn bind_mount(self, mount: impl Into<String>) -> Self
Add a bind mount.
Sourcepub fn validate_sandbox_policy(
&self,
policy: &SandboxPolicy,
) -> Result<(), ExecutionError>
pub fn validate_sandbox_policy( &self, policy: &SandboxPolicy, ) -> Result<(), ExecutionError>
Checks that a container created from this configuration satisfies policy.
A persistent container’s network mode, bind mounts, and environment are
fixed when it is created, so a request cannot narrow them afterwards.
DockerExecutor calls this before every execution and rejects a request
whose policy is stricter than the container:
| Policy | Satisfied when |
|---|---|
NetworkPolicy::Disabled | network_disabled is true |
FilesystemPolicy::None | there are no bind mounts |
FilesystemPolicy::WorkspaceReadOnly { root } | every bind mount is read-only (:ro) and its host path lies under root |
FilesystemPolicy::WorkspaceReadWrite { root } | every bind mount’s host path lies under root |
FilesystemPolicy::Paths { read_only, read_write } | every bind mount lies under a read_write path, or is read-only and lies under a read_only path |
EnvironmentPolicy::None | environment is empty |
EnvironmentPolicy::AllowList(names) | every environment entry’s name is in names |
Bind-mount host paths must be absolute and free of .. components, so a
named volume never satisfies a filesystem policy. Variables defined by the
image itself (PATH, LANG) come from the image, not the host, and are
not checked.
§Errors
Returns ExecutionError::UnsupportedPolicy naming the first setting
that exceeds the policy.
§Example
use adk_code::{DockerConfig, NetworkPolicy, SandboxPolicy};
let strict = SandboxPolicy::strict_rust();
assert!(DockerConfig::python().validate_sandbox_policy(&strict).is_ok());
// A networked container cannot honour a request that disables the network.
let networked = DockerConfig::python().with_network();
assert!(networked.validate_sandbox_policy(&strict).is_err());
let allows_network = SandboxPolicy { network: NetworkPolicy::Enabled, ..strict };
assert!(networked.validate_sandbox_policy(&allows_network).is_ok());