-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Description
The directory field in CreateSessionRequest is accepted by the API and stored in SessionState, but it's never passed to the agent process. This means agents always run in sandbox-agent's current working directory instead of the requested directory.
Current Behavior
When creating a session via POST /v1/sessions/{session_id} with a directory parameter:
curl -X POST http://localhost:2468/v1/sessions/my-session \
-H "Content-Type: application/json" \
-d '{
"agent": "claude",
"directory": "/path/to/project"
}'The agent process ignores the directory and runs in std::env::current_dir() (the directory where sandbox-agent was started).
Expected Behavior
The agent should execute with its working directory set to the requested directory path.
Root Cause
The directory field is lost during the conversion from SessionState to SessionSnapshot:
- ✅
CreateSessionRequest.directoryis received (router.rs:4701) - ✅ Stored in
SessionState.directory(router.rs:504) - ❌ Not included in
SessionSnapshotstruct (router.rs:8129-8137) - ❌ Not set in
SpawnOptions.working_dirbybuild_spawn_options()(router.rs:5711-5765) - Falls back to default in agent-management (agents.rs:207-212)
Code Locations
1. SessionSnapshot missing directory field:
// server/packages/sandbox-agent/src/router.rs:8129-8137
#[derive(Clone, Debug)]
struct SessionSnapshot {
session_id: String,
agent: AgentId,
agent_mode: String,
permission_mode: String,
model: Option<String>,
variant: Option<String>,
native_session_id: Option<String>,
// ❌ Missing: directory: Option<String>,
}2. From implementation doesn't copy directory:
// server/packages/sandbox-agent/src/router.rs:8139-8151
impl From<&SessionState> for SessionSnapshot {
fn from(session: &SessionState) -> Self {
Self {
// ...
native_session_id: session.native_session_id.clone(),
// ❌ Missing: directory: session.directory.clone(),
}
}
}3. build_spawn_options doesn't set working_dir:
// server/packages/sandbox-agent/src/router.rs:5711-5765
fn build_spawn_options(
session: &SessionSnapshot,
prompt: String,
credentials: ExtractedCredentials,
) -> SpawnOptions {
let mut options = SpawnOptions::new(prompt);
options.model = session.model.clone();
options.variant = session.variant.clone();
// ...
// ❌ Missing: options.working_dir = session.directory.as_ref().map(PathBuf::from);
options
}Proposed Fix
Add directory to the data flow:
- Add
directory: Option<String>field toSessionSnapshotstruct - Copy
directoryinFrom<&SessionState> for SessionSnapshotimplementation - Set
options.working_dirinbuild_spawn_options():options.working_dir = session.directory.as_ref().map(PathBuf::from);
Impact
- Affects all agents (Claude, Codex, OpenCode, Amp)
- Breaks use cases where users need agents to run in specific project directories
- API accepts the parameter but silently ignores it (surprising behavior)
Workaround
Currently, users must start sandbox-agent in the desired working directory, which doesn't work for multi-session scenarios with different directories.