Work around Daytona SDK missing env support in exec_command

The Daytona toolbox API's ExecuteRequest struct has no env field,
so ExecuteCommandOptions.env is silently dropped. Prepend export
statements to the command string to inject env vars into the shell.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-03-07 23:59:40 -05:00
parent 95854936e8
commit 3748fea9d5

View file

@ -896,9 +896,29 @@ impl Sandbox for DaytonaSandbox {
timeout: Some(std::time::Duration::from_millis(timeout_ms)),
};
// The Daytona toolbox API's ExecuteRequest does not support an `env`
// field, so we prepend `export` statements to inject env vars into the
// shell session before the actual command runs.
let command_with_env = if let Some(vars) = env_vars {
if !vars.is_empty() {
let exports: Vec<String> = vars
.iter()
.map(|(k, v)| {
let escaped = v.replace('\'', "'\\''");
format!("export {k}='{escaped}'")
})
.collect();
format!("{}\n{}", exports.join("\n"), command)
} else {
command.to_string()
}
} else {
command.to_string()
};
// Wrap with `bash -c` so pipes, env vars, and shell features work.
// The Daytona API uses direct exec, not a shell.
let wrapped = wrap_bash_command(command);
let wrapped = wrap_bash_command(&command_with_env);
let result = process_svc
.execute_command(&wrapped, options)
.await