An open-source, faster Devin alternative
TypeScript
Move sandbox env vars into the in-VM agent
motatoes0b6a2196b3ce
diff --git a/internal/agent/exec.go b/internal/agent/exec.goindex fb6bf836..8a240e44 100644--- a/internal/agent/exec.go+++ b/internal/agent/exec.go@@ -27,6 +27,16 @@ func baseEnv() []string {return env}+// SetEnvs stores sandbox-level environment variables that are injected into+// every subsequent Exec/ExecStream call. Safe to call multiple times; last write wins.+func (s *Server) SetEnvs(ctx context.Context, req *pb.SetEnvsRequest) (*pb.SetEnvsResponse, error) {+ envs := mapToEnv(req.Envs)+ s.envMu.Lock()+ s.sandboxEnvs = envs+ s.envMu.Unlock()+ return &pb.SetEnvsResponse{}, nil+}+// Exec runs a command synchronously and returns stdout/stderr/exit code.func (s *Server) Exec(ctx context.Context, req *pb.ExecRequest) (*pb.ExecResponse, error) {timeout := time.Duration(req.TimeoutSeconds) * time.Second@@ -46,8 +56,13 @@ func (s *Server) Exec(ctx context.Context, req *pb.ExecRequest) (*pb.ExecResponscmd.Dir = "/workspace"}- // Set environment variables with HOME=/workspace+ // Build env: base < sandbox-level < per-commandcmd.Env = baseEnv()+ s.envMu.RLock()+ if len(s.sandboxEnvs) > 0 {+ cmd.Env = append(cmd.Env, s.sandboxEnvs...)+ }+ s.envMu.RUnlock()if len(req.Envs) > 0 {cmd.Env = append(cmd.Env, mapToEnv(req.Envs)...)}@@ -101,7 +116,13 @@ func (s *Server) ExecStream(req *pb.ExecRequest, stream pb.SandboxAgent_ExecStrecmd.Dir = "/workspace"}+ // Build env: base < sandbox-level < per-commandcmd.Env = baseEnv()+ s.envMu.RLock()+ if len(s.sandboxEnvs) > 0 {+ cmd.Env = append(cmd.Env, s.sandboxEnvs...)+ }+ s.envMu.RUnlock()if len(req.Envs) > 0 {cmd.Env = append(cmd.Env, mapToEnv(req.Envs)...)}diff --git a/internal/agent/server.go b/internal/agent/server.goindex 1456955c..94d7c447 100644--- a/internal/agent/server.go+++ b/internal/agent/server.go@@ -38,6 +38,11 @@ type Server struct {// Set by the main package based on the platform (vsock or unix).ListenPort ListenPortFunc+ // Sandbox-level environment variables (set once via SetEnvs RPC).+ // Injected into every Exec/ExecStream between baseEnv and per-command envs.+ envMu sync.RWMutex+ sandboxEnvs []string+// PTY sessionsptyMu sync.MutexptySessions map[string]*ptySessiondiff --git a/internal/firecracker/agent_client.go b/internal/firecracker/agent_client.goindex 158cb238..af6460f5 100644--- a/internal/firecracker/agent_client.go+++ b/internal/firecracker/agent_client.go@@ -121,6 +121,12 @@ func (c *AgentClient) Close() error {return c.conn.Close()}+// SetEnvs sends sandbox-level environment variables to the in-VM agent.+func (c *AgentClient) SetEnvs(ctx context.Context, envs map[string]string) error {+ _, err := c.client.SetEnvs(ctx, &pb.SetEnvsRequest{Envs: envs})+ return err+}+// Ping verifies the agent is responsive.func (c *AgentClient) Ping(ctx context.Context) (*pb.PingResponse, error) {return c.client.Ping(ctx, &pb.PingRequest{})diff --git a/internal/firecracker/manager.go b/internal/firecracker/manager.goindex e04f598b..44401acf 100644--- a/internal/firecracker/manager.go+++ b/internal/firecracker/manager.go@@ -36,7 +36,6 @@ type VMInstance struct {MemoryMB intHostPort intGuestPort int- Envs map[string]string // sandbox-level environment variables// VM internalspid int // Firecracker VMM process PID@@ -62,7 +61,6 @@ type SandboxMeta struct {CpuCount int `json:"cpuCount"`MemoryMB int `json:"memoryMB"`GuestPort int `json:"guestPort"`- Envs map[string]string `json:"envs,omitempty"`}// Config holds configuration for the Firecracker Manager.@@ -379,7 +377,6 @@ func (m *Manager) createWithID(ctx context.Context, id string, cfg types.SandboxMemoryMB: memMB,HostPort: hostPort,GuestPort: guestPort,- Envs: cfg.Envs,pid: cmd.Process.Pid,cmd: cmd,network: netCfg,@@ -403,6 +400,16 @@ func (m *Manager) createWithID(ctx context.Context, id string, cfg types.Sandbox}vm.agent = agentClient+ // Send sandbox-level env vars into the VM agent (survives snapshots)+ if len(cfg.Envs) > 0 {+ envCtx, envCancel := context.WithTimeout(context.Background(), 5*time.Second)+ if err := agentClient.SetEnvs(envCtx, cfg.Envs); err != nil {+ envCancel()+ log.Printf("firecracker: warning: SetEnvs failed for %s: %v", id, err)+ }+ envCancel()+ }+// Register VMm.mu.Lock()m.vms[id] = vm@@ -415,7 +422,6 @@ func (m *Manager) createWithID(ctx context.Context, id string, cfg types.SandboxCpuCount: cpus,MemoryMB: memMB,GuestPort: guestPort,- Envs: cfg.Envs,}if metaJSON, err := json.Marshal(sbMeta); err == nil {_ = os.WriteFile(filepath.Join(sandboxDir, "sandbox-meta.json"), metaJSON, 0644)@@ -673,19 +679,10 @@ func (m *Manager) Exec(ctx context.Context, sandboxID string, cfg types.ProcessCcommand = "/bin/sh"}- // Merge sandbox-level envs with per-command envs (per-command takes precedence)- envs := make(map[string]string, len(vm.Envs)+len(cfg.Env))- for k, v := range vm.Envs {- envs[k] = v- }- for k, v := range cfg.Env {- envs[k] = v- }-resp, err := vm.agent.Exec(ctx, &pb.ExecRequest{Command: command,Args: args,- Envs: envs,+ Envs: cfg.Env,Cwd: cfg.Cwd,TimeoutSeconds: timeout,})@@ -1066,7 +1063,6 @@ func (m *Manager) RecoverLocalSandboxes() []LocalRecovery {CpuCount: snapMeta.CpuCount,MemoryMB: snapMeta.MemoryMB,GuestPort: snapMeta.GuestPort,- Envs: snapMeta.Envs,},})continuediff --git a/internal/firecracker/snapshot.go b/internal/firecracker/snapshot.goindex d7b8c010..e436ef7a 100644--- a/internal/firecracker/snapshot.go+++ b/internal/firecracker/snapshot.go@@ -37,7 +37,6 @@ type SnapshotMeta struct {MemoryMB int `json:"memoryMB"`Template string `json:"template"`GuestPort int `json:"guestPort"`- Envs map[string]string `json:"envs,omitempty"`}// doHibernate pauses a running VM, creates a full memory snapshot, and kicks off@@ -123,7 +122,6 @@ func (m *Manager) doHibernate(ctx context.Context, vm *VMInstance, checkpointStoMemoryMB: vm.MemoryMB,Template: vm.Template,GuestPort: vm.GuestPort,- Envs: vm.Envs,}metaJSON, err := json.Marshal(meta)if err != nil {@@ -465,7 +463,6 @@ func (m *Manager) doWake(ctx context.Context, sandboxID, checkpointKey string, cMemoryMB: meta.MemoryMB,HostPort: hostPort,GuestPort: netCfg.GuestPort,- Envs: meta.Envs,pid: cmd.Process.Pid,cmd: cmd,network: netCfg,@@ -661,7 +658,6 @@ func (m *Manager) coldBootLocal(ctx context.Context, sandboxID string, timeout iMemoryMB: memMB,HostPort: hostPort,GuestPort: guestPort,- Envs: meta.Envs,pid: cmd.Process.Pid,cmd: cmd,network: netCfg,@@ -1051,7 +1047,6 @@ func (m *Manager) CreateCheckpoint(ctx context.Context, sandboxID, checkpointIDMemoryMB: vm.MemoryMB,Template: vm.Template,GuestPort: vm.GuestPort,- Envs: vm.Envs,}metaJSON, _ := json.MarshalIndent(meta, "", " ")if writeErr := os.WriteFile(filepath.Join(snapshotDir, "snapshot-meta.json"), metaJSON, 0644); writeErr != nil {@@ -1309,7 +1304,6 @@ func (m *Manager) warmRestoreFromCheckpoint(ctx context.Context, vm *VMInstance,MemoryMB: meta.MemoryMB,HostPort: hostPort,GuestPort: netCfg.GuestPort,- Envs: meta.Envs,pid: cmd.Process.Pid,cmd: cmd,network: netCfg,@@ -1372,13 +1366,11 @@ func (m *Manager) coldBootRestoreFromCheckpoint(ctx context.Context, vm *VMInstacpuCount := 0memoryMB := 0guestPort := 0- var envs map[string]stringif vm != nil {template = vm.TemplatecpuCount = vm.CpuCountmemoryMB = vm.MemoryMBguestPort = vm.GuestPort- envs = vm.Envs}cfg := types.SandboxConfig{@@ -1386,7 +1378,6 @@ func (m *Manager) coldBootRestoreFromCheckpoint(ctx context.Context, vm *VMInstaCpuCount: cpuCount,MemoryMB: memoryMB,Port: guestPort,- Envs: envs,NetworkEnabled: true,TemplateRootfsKey: "local://" + cachedRootfs,TemplateWorkspaceKey: "local://" + cachedWorkspace,@@ -1807,6 +1798,16 @@ func (m *Manager) warmForkFromCheckpoint(ctx context.Context, checkpointID strin// Don't fail — the VM is running and accessible via vsock, just external network may be broken}+ // Send sandbox-level env vars into the forked VM agent+ if len(cfg.Envs) > 0 {+ envCtx, envCancel := context.WithTimeout(context.Background(), 5*time.Second)+ if err := agentClient.SetEnvs(envCtx, cfg.Envs); err != nil {+ envCancel()+ log.Printf("firecracker: warning: SetEnvs failed for %s: %v", newID, err)+ }+ envCancel()+ }+// Step 11: Write sandbox-meta.json for crash recoverysbMeta := SandboxMeta{SandboxID: newID,@@ -1814,7 +1815,6 @@ func (m *Manager) warmForkFromCheckpoint(ctx context.Context, checkpointID strinCpuCount: meta.CpuCount,MemoryMB: meta.MemoryMB,GuestPort: netCfg.GuestPort,- Envs: cfg.Envs,}sbMetaJSON, _ := json.Marshal(sbMeta)_ = os.WriteFile(filepath.Join(sandboxDir, "sandbox-meta.json"), sbMetaJSON, 0644)@@ -1836,7 +1836,6 @@ func (m *Manager) warmForkFromCheckpoint(ctx context.Context, checkpointID strinMemoryMB: meta.MemoryMB,HostPort: hostPort,GuestPort: netCfg.GuestPort,- Envs: cfg.Envs,pid: cmd.Process.Pid,cmd: cmd,network: netCfg,@@ -2262,6 +2261,16 @@ func (m *Manager) createFromGoldenSnapshot(ctx context.Context, id string, cfg tlog.Printf("firecracker: goldenCreate %s: network reconfig failed: %v (VM still running)", id, err)}+ // Send sandbox-level env vars into the VM agent+ if len(cfg.Envs) > 0 {+ envCtx, envCancel := context.WithTimeout(context.Background(), 5*time.Second)+ if err := agentClient.SetEnvs(envCtx, cfg.Envs); err != nil {+ envCancel()+ log.Printf("firecracker: warning: SetEnvs failed for %s: %v", id, err)+ }+ envCancel()+ }+// Step 9: Write sandbox-meta.jsoncpus := cfg.CpuCountif cpus <= 0 {@@ -2278,7 +2287,6 @@ func (m *Manager) createFromGoldenSnapshot(ctx context.Context, id string, cfg tCpuCount: cpus,MemoryMB: memMB,GuestPort: guestPort,- Envs: cfg.Envs,}sbMetaJSON, _ := json.Marshal(sbMeta)_ = os.WriteFile(filepath.Join(sandboxDir, "sandbox-meta.json"), sbMetaJSON, 0644)@@ -2300,7 +2308,6 @@ func (m *Manager) createFromGoldenSnapshot(ctx context.Context, id string, cfg tMemoryMB: memMB,HostPort: hostPort,GuestPort: guestPort,- Envs: cfg.Envs,pid: cmd.Process.Pid,cmd: cmd,network: netCfg,diff --git a/proto/agent/agent.pb.go b/proto/agent/agent.pb.goindex 32d5165d..170a4345 100644--- a/proto/agent/agent.pb.go+++ b/proto/agent/agent.pb.go@@ -1,7 +1,7 @@// Code generated by protoc-gen-go. DO NOT EDIT.// versions:// protoc-gen-go v1.36.11-// protoc v6.33.4+// protoc v7.34.0// source: proto/agent/agent.protopackage agent@@ -1467,6 +1467,86 @@ func (*PTYKillResponse) Descriptor() ([]byte, []int) {return file_proto_agent_agent_proto_rawDescGZIP(), []int{27}}+type SetEnvsRequest struct {+ state protoimpl.MessageState `protogen:"open.v1"`+ Envs map[string]string `protobuf:"bytes,1,rep,name=envs,proto3" json:"envs,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`+ unknownFields protoimpl.UnknownFields+ sizeCache protoimpl.SizeCache+}++func (x *SetEnvsRequest) Reset() {+ *x = SetEnvsRequest{}+ mi := &file_proto_agent_agent_proto_msgTypes[28]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+}++func (x *SetEnvsRequest) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*SetEnvsRequest) ProtoMessage() {}++func (x *SetEnvsRequest) ProtoReflect() protoreflect.Message {+ mi := &file_proto_agent_agent_proto_msgTypes[28]+ if x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use SetEnvsRequest.ProtoReflect.Descriptor instead.+func (*SetEnvsRequest) Descriptor() ([]byte, []int) {+ return file_proto_agent_agent_proto_rawDescGZIP(), []int{28}+}++func (x *SetEnvsRequest) GetEnvs() map[string]string {+ if x != nil {+ return x.Envs+ }+ return nil+}++type SetEnvsResponse struct {+ state protoimpl.MessageState `protogen:"open.v1"`+ unknownFields protoimpl.UnknownFields+ sizeCache protoimpl.SizeCache+}++func (x *SetEnvsResponse) Reset() {+ *x = SetEnvsResponse{}+ mi := &file_proto_agent_agent_proto_msgTypes[29]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+}++func (x *SetEnvsResponse) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*SetEnvsResponse) ProtoMessage() {}++func (x *SetEnvsResponse) ProtoReflect() protoreflect.Message {+ mi := &file_proto_agent_agent_proto_msgTypes[29]+ if x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use SetEnvsResponse.ProtoReflect.Descriptor instead.+func (*SetEnvsResponse) Descriptor() ([]byte, []int) {+ return file_proto_agent_agent_proto_rawDescGZIP(), []int{29}+}+type ShutdownRequest struct {state protoimpl.MessageState `protogen:"open.v1"`unknownFields protoimpl.UnknownFields@@ -1475,7 +1555,7 @@ type ShutdownRequest struct {func (x *ShutdownRequest) Reset() {*x = ShutdownRequest{}- mi := &file_proto_agent_agent_proto_msgTypes[28]+ mi := &file_proto_agent_agent_proto_msgTypes[30]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -1487,7 +1567,7 @@ func (x *ShutdownRequest) String() string {func (*ShutdownRequest) ProtoMessage() {}func (x *ShutdownRequest) ProtoReflect() protoreflect.Message {- mi := &file_proto_agent_agent_proto_msgTypes[28]+ mi := &file_proto_agent_agent_proto_msgTypes[30]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -1500,7 +1580,7 @@ func (x *ShutdownRequest) ProtoReflect() protoreflect.Message {// Deprecated: Use ShutdownRequest.ProtoReflect.Descriptor instead.func (*ShutdownRequest) Descriptor() ([]byte, []int) {- return file_proto_agent_agent_proto_rawDescGZIP(), []int{28}+ return file_proto_agent_agent_proto_rawDescGZIP(), []int{30}}type ShutdownResponse struct {@@ -1511,7 +1591,7 @@ type ShutdownResponse struct {func (x *ShutdownResponse) Reset() {*x = ShutdownResponse{}- mi := &file_proto_agent_agent_proto_msgTypes[29]+ mi := &file_proto_agent_agent_proto_msgTypes[31]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -1523,7 +1603,7 @@ func (x *ShutdownResponse) String() string {func (*ShutdownResponse) ProtoMessage() {}func (x *ShutdownResponse) ProtoReflect() protoreflect.Message {- mi := &file_proto_agent_agent_proto_msgTypes[29]+ mi := &file_proto_agent_agent_proto_msgTypes[31]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -1536,7 +1616,7 @@ func (x *ShutdownResponse) ProtoReflect() protoreflect.Message {// Deprecated: Use ShutdownResponse.ProtoReflect.Descriptor instead.func (*ShutdownResponse) Descriptor() ([]byte, []int) {- return file_proto_agent_agent_proto_rawDescGZIP(), []int{29}+ return file_proto_agent_agent_proto_rawDescGZIP(), []int{31}}type SyncFSRequest struct {@@ -1547,7 +1627,7 @@ type SyncFSRequest struct {func (x *SyncFSRequest) Reset() {*x = SyncFSRequest{}- mi := &file_proto_agent_agent_proto_msgTypes[30]+ mi := &file_proto_agent_agent_proto_msgTypes[32]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -1559,7 +1639,7 @@ func (x *SyncFSRequest) String() string {func (*SyncFSRequest) ProtoMessage() {}func (x *SyncFSRequest) ProtoReflect() protoreflect.Message {- mi := &file_proto_agent_agent_proto_msgTypes[30]+ mi := &file_proto_agent_agent_proto_msgTypes[32]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -1572,7 +1652,7 @@ func (x *SyncFSRequest) ProtoReflect() protoreflect.Message {// Deprecated: Use SyncFSRequest.ProtoReflect.Descriptor instead.func (*SyncFSRequest) Descriptor() ([]byte, []int) {- return file_proto_agent_agent_proto_rawDescGZIP(), []int{30}+ return file_proto_agent_agent_proto_rawDescGZIP(), []int{32}}type SyncFSResponse struct {@@ -1583,7 +1663,7 @@ type SyncFSResponse struct {func (x *SyncFSResponse) Reset() {*x = SyncFSResponse{}- mi := &file_proto_agent_agent_proto_msgTypes[31]+ mi := &file_proto_agent_agent_proto_msgTypes[33]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -1595,7 +1675,7 @@ func (x *SyncFSResponse) String() string {func (*SyncFSResponse) ProtoMessage() {}func (x *SyncFSResponse) ProtoReflect() protoreflect.Message {- mi := &file_proto_agent_agent_proto_msgTypes[31]+ mi := &file_proto_agent_agent_proto_msgTypes[33]if x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -1608,7 +1688,7 @@ func (x *SyncFSResponse) ProtoReflect() protoreflect.Message {// Deprecated: Use SyncFSResponse.ProtoReflect.Descriptor instead.func (*SyncFSResponse) Descriptor() ([]byte, []int) {- return file_proto_agent_agent_proto_rawDescGZIP(), []int{31}+ return file_proto_agent_agent_proto_rawDescGZIP(), []int{33}}var File_proto_agent_agent_proto protoreflect.FileDescriptor@@ -1705,11 +1785,17 @@ const file_proto_agent_agent_proto_rawDesc = "" +"\x0ePTYKillRequest\x12\x1d\n" +"\n" +"session_id\x18\x01 \x01(\tR\tsessionId\"\x11\n" +- "\x0fPTYKillResponse\"\x11\n" ++ "\x0fPTYKillResponse\"~\n" ++ "\x0eSetEnvsRequest\x123\n" ++ "\x04envs\x18\x01 \x03(\v2\x1f.agent.SetEnvsRequest.EnvsEntryR\x04envs\x1a7\n" ++ "\tEnvsEntry\x12\x10\n" ++ "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" ++ "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\x11\n" ++ "\x0fSetEnvsResponse\"\x11\n" +"\x0fShutdownRequest\"\x12\n" +"\x10ShutdownResponse\"\x0f\n" +"\rSyncFSRequest\"\x10\n" +- "\x0eSyncFSResponse2\x9e\a\n" ++ "\x0eSyncFSResponse2\xd8\a\n" +"\fSandboxAgent\x12/\n" +"\x04Exec\x12\x12.agent.ExecRequest\x1a\x13.agent.ExecResponse\x12:\n" +"\n" +@@ -1725,7 +1811,8 @@ const file_proto_agent_agent_proto_rawDesc = "" +"\x04Ping\x12\x12.agent.PingRequest\x1a\x13.agent.PingResponse\x12>\n" +"\tPTYCreate\x12\x17.agent.PTYCreateRequest\x1a\x18.agent.PTYCreateResponse\x12>\n" +"\tPTYResize\x12\x17.agent.PTYResizeRequest\x1a\x18.agent.PTYResizeResponse\x128\n" +- "\aPTYKill\x12\x15.agent.PTYKillRequest\x1a\x16.agent.PTYKillResponse\x12;\n" ++ "\aPTYKill\x12\x15.agent.PTYKillRequest\x1a\x16.agent.PTYKillResponse\x128\n" ++ "\aSetEnvs\x12\x15.agent.SetEnvsRequest\x1a\x16.agent.SetEnvsResponse\x12;\n" +"\bShutdown\x12\x16.agent.ShutdownRequest\x1a\x17.agent.ShutdownResponse\x125\n" +"\x06SyncFS\x12\x14.agent.SyncFSRequest\x1a\x15.agent.SyncFSResponseB0Z.github.com/opensandbox/opensandbox/proto/agentb\x06proto3"@@ -1742,7 +1829,7 @@ func file_proto_agent_agent_proto_rawDescGZIP() []byte {}var file_proto_agent_agent_proto_enumTypes = make([]protoimpl.EnumInfo, 1)-var file_proto_agent_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 33)+var file_proto_agent_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 36)var file_proto_agent_agent_proto_goTypes = []any{(ExecOutputChunk_Stream)(0), // 0: agent.ExecOutputChunk.Stream(*ExecRequest)(nil), // 1: agent.ExecRequest@@ -1773,53 +1860,59 @@ var file_proto_agent_agent_proto_goTypes = []any{(*PTYResizeResponse)(nil), // 26: agent.PTYResizeResponse(*PTYKillRequest)(nil), // 27: agent.PTYKillRequest(*PTYKillResponse)(nil), // 28: agent.PTYKillResponse- (*ShutdownRequest)(nil), // 29: agent.ShutdownRequest- (*ShutdownResponse)(nil), // 30: agent.ShutdownResponse- (*SyncFSRequest)(nil), // 31: agent.SyncFSRequest- (*SyncFSResponse)(nil), // 32: agent.SyncFSResponse- nil, // 33: agent.ExecRequest.EnvsEntry+ (*SetEnvsRequest)(nil), // 29: agent.SetEnvsRequest+ (*SetEnvsResponse)(nil), // 30: agent.SetEnvsResponse+ (*ShutdownRequest)(nil), // 31: agent.ShutdownRequest+ (*ShutdownResponse)(nil), // 32: agent.ShutdownResponse+ (*SyncFSRequest)(nil), // 33: agent.SyncFSRequest+ (*SyncFSResponse)(nil), // 34: agent.SyncFSResponse+ nil, // 35: agent.ExecRequest.EnvsEntry+ nil, // 36: agent.SetEnvsRequest.EnvsEntry}var file_proto_agent_agent_proto_depIdxs = []int32{- 33, // 0: agent.ExecRequest.envs:type_name -> agent.ExecRequest.EnvsEntry+ 35, // 0: agent.ExecRequest.envs:type_name -> agent.ExecRequest.EnvsEntry0, // 1: agent.ExecOutputChunk.stream:type_name -> agent.ExecOutputChunk.Stream9, // 2: agent.ListDirResponse.entries:type_name -> agent.DirEntry- 1, // 3: agent.SandboxAgent.Exec:input_type -> agent.ExecRequest- 1, // 4: agent.SandboxAgent.ExecStream:input_type -> agent.ExecRequest- 4, // 5: agent.SandboxAgent.ReadFile:input_type -> agent.ReadFileRequest- 6, // 6: agent.SandboxAgent.WriteFile:input_type -> agent.WriteFileRequest- 8, // 7: agent.SandboxAgent.ListDir:input_type -> agent.ListDirRequest- 11, // 8: agent.SandboxAgent.MakeDir:input_type -> agent.MakeDirRequest- 13, // 9: agent.SandboxAgent.Remove:input_type -> agent.RemoveRequest- 15, // 10: agent.SandboxAgent.Exists:input_type -> agent.ExistsRequest- 17, // 11: agent.SandboxAgent.Stat:input_type -> agent.StatRequest- 19, // 12: agent.SandboxAgent.Stats:input_type -> agent.StatsRequest- 21, // 13: agent.SandboxAgent.Ping:input_type -> agent.PingRequest- 23, // 14: agent.SandboxAgent.PTYCreate:input_type -> agent.PTYCreateRequest- 25, // 15: agent.SandboxAgent.PTYResize:input_type -> agent.PTYResizeRequest- 27, // 16: agent.SandboxAgent.PTYKill:input_type -> agent.PTYKillRequest- 29, // 17: agent.SandboxAgent.Shutdown:input_type -> agent.ShutdownRequest- 31, // 18: agent.SandboxAgent.SyncFS:input_type -> agent.SyncFSRequest- 2, // 19: agent.SandboxAgent.Exec:output_type -> agent.ExecResponse- 3, // 20: agent.SandboxAgent.ExecStream:output_type -> agent.ExecOutputChunk- 5, // 21: agent.SandboxAgent.ReadFile:output_type -> agent.ReadFileResponse- 7, // 22: agent.SandboxAgent.WriteFile:output_type -> agent.WriteFileResponse- 10, // 23: agent.SandboxAgent.ListDir:output_type -> agent.ListDirResponse- 12, // 24: agent.SandboxAgent.MakeDir:output_type -> agent.MakeDirResponse- 14, // 25: agent.SandboxAgent.Remove:output_type -> agent.RemoveResponse- 16, // 26: agent.SandboxAgent.Exists:output_type -> agent.ExistsResponse- 18, // 27: agent.SandboxAgent.Stat:output_type -> agent.StatResponse- 20, // 28: agent.SandboxAgent.Stats:output_type -> agent.StatsResponse- 22, // 29: agent.SandboxAgent.Ping:output_type -> agent.PingResponse- 24, // 30: agent.SandboxAgent.PTYCreate:output_type -> agent.PTYCreateResponse- 26, // 31: agent.SandboxAgent.PTYResize:output_type -> agent.PTYResizeResponse- 28, // 32: agent.SandboxAgent.PTYKill:output_type -> agent.PTYKillResponse- 30, // 33: agent.SandboxAgent.Shutdown:output_type -> agent.ShutdownResponse- 32, // 34: agent.SandboxAgent.SyncFS:output_type -> agent.SyncFSResponse- 19, // [19:35] is the sub-list for method output_type- 3, // [3:19] is the sub-list for method input_type- 3, // [3:3] is the sub-list for extension type_name- 3, // [3:3] is the sub-list for extension extendee- 0, // [0:3] is the sub-list for field type_name+ 36, // 3: agent.SetEnvsRequest.envs:type_name -> agent.SetEnvsRequest.EnvsEntry+ 1, // 4: agent.SandboxAgent.Exec:input_type -> agent.ExecRequest+ 1, // 5: agent.SandboxAgent.ExecStream:input_type -> agent.ExecRequest+ 4, // 6: agent.SandboxAgent.ReadFile:input_type -> agent.ReadFileRequest+ 6, // 7: agent.SandboxAgent.WriteFile:input_type -> agent.WriteFileRequest+ 8, // 8: agent.SandboxAgent.ListDir:input_type -> agent.ListDirRequest+ 11, // 9: agent.SandboxAgent.MakeDir:input_type -> agent.MakeDirRequest+ 13, // 10: agent.SandboxAgent.Remove:input_type -> agent.RemoveRequest+ 15, // 11: agent.SandboxAgent.Exists:input_type -> agent.ExistsRequest+ 17, // 12: agent.SandboxAgent.Stat:input_type -> agent.StatRequest+ 19, // 13: agent.SandboxAgent.Stats:input_type -> agent.StatsRequest+ 21, // 14: agent.SandboxAgent.Ping:input_type -> agent.PingRequest+ 23, // 15: agent.SandboxAgent.PTYCreate:input_type -> agent.PTYCreateRequest+ 25, // 16: agent.SandboxAgent.PTYResize:input_type -> agent.PTYResizeRequest+ 27, // 17: agent.SandboxAgent.PTYKill:input_type -> agent.PTYKillRequest+ 29, // 18: agent.SandboxAgent.SetEnvs:input_type -> agent.SetEnvsRequest+ 31, // 19: agent.SandboxAgent.Shutdown:input_type -> agent.ShutdownRequest+ 33, // 20: agent.SandboxAgent.SyncFS:input_type -> agent.SyncFSRequest+ 2, // 21: agent.SandboxAgent.Exec:output_type -> agent.ExecResponse+ 3, // 22: agent.SandboxAgent.ExecStream:output_type -> agent.ExecOutputChunk+ 5, // 23: agent.SandboxAgent.ReadFile:output_type -> agent.ReadFileResponse+ 7, // 24: agent.SandboxAgent.WriteFile:output_type -> agent.WriteFileResponse+ 10, // 25: agent.SandboxAgent.ListDir:output_type -> agent.ListDirResponse+ 12, // 26: agent.SandboxAgent.MakeDir:output_type -> agent.MakeDirResponse+ 14, // 27: agent.SandboxAgent.Remove:output_type -> agent.RemoveResponse+ 16, // 28: agent.SandboxAgent.Exists:output_type -> agent.ExistsResponse+ 18, // 29: agent.SandboxAgent.Stat:output_type -> agent.StatResponse+ 20, // 30: agent.SandboxAgent.Stats:output_type -> agent.StatsResponse+ 22, // 31: agent.SandboxAgent.Ping:output_type -> agent.PingResponse+ 24, // 32: agent.SandboxAgent.PTYCreate:output_type -> agent.PTYCreateResponse+ 26, // 33: agent.SandboxAgent.PTYResize:output_type -> agent.PTYResizeResponse+ 28, // 34: agent.SandboxAgent.PTYKill:output_type -> agent.PTYKillResponse+ 30, // 35: agent.SandboxAgent.SetEnvs:output_type -> agent.SetEnvsResponse+ 32, // 36: agent.SandboxAgent.Shutdown:output_type -> agent.ShutdownResponse+ 34, // 37: agent.SandboxAgent.SyncFS:output_type -> agent.SyncFSResponse+ 21, // [21:38] is the sub-list for method output_type+ 4, // [4:21] is the sub-list for method input_type+ 4, // [4:4] is the sub-list for extension type_name+ 4, // [4:4] is the sub-list for extension extendee+ 0, // [0:4] is the sub-list for field type_name}func init() { file_proto_agent_agent_proto_init() }@@ -1833,7 +1926,7 @@ func file_proto_agent_agent_proto_init() {GoPackagePath: reflect.TypeOf(x{}).PkgPath(),RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_agent_agent_proto_rawDesc), len(file_proto_agent_agent_proto_rawDesc)),NumEnums: 1,- NumMessages: 33,+ NumMessages: 36,NumExtensions: 0,NumServices: 1,},diff --git a/proto/agent/agent.proto b/proto/agent/agent.protoindex 92c5aa4a..9b520f7e 100644--- a/proto/agent/agent.proto+++ b/proto/agent/agent.proto@@ -33,6 +33,11 @@ service SandboxAgent {rpc PTYResize(PTYResizeRequest) returns (PTYResizeResponse);rpc PTYKill(PTYKillRequest) returns (PTYKillResponse);+ // SetEnvs stores sandbox-level environment variables inside the agent.+ // These are injected into every subsequent Exec/ExecStream call,+ // between the base OS env and per-command envs.+ rpc SetEnvs(SetEnvsRequest) returns (SetEnvsResponse);+// Shutdown gracefully terminates the agent and syncs disks.rpc Shutdown(ShutdownRequest) returns (ShutdownResponse);@@ -181,6 +186,14 @@ message PTYKillRequest {message PTYKillResponse {}+// --- SetEnvs ---++message SetEnvsRequest {+ map<string, string> envs = 1;+}++message SetEnvsResponse {}+// --- Shutdown ---message ShutdownRequest {}diff --git a/proto/agent/agent_grpc.pb.go b/proto/agent/agent_grpc.pb.goindex 6beca548..a5a4fe92 100644--- a/proto/agent/agent_grpc.pb.go+++ b/proto/agent/agent_grpc.pb.go@@ -1,7 +1,7 @@// Code generated by protoc-gen-go-grpc. DO NOT EDIT.// versions:// - protoc-gen-go-grpc v1.6.1-// - protoc v6.33.4+// - protoc v7.34.0// source: proto/agent/agent.protopackage agent@@ -33,6 +33,7 @@ const (SandboxAgent_PTYCreate_FullMethodName = "/agent.SandboxAgent/PTYCreate"SandboxAgent_PTYResize_FullMethodName = "/agent.SandboxAgent/PTYResize"SandboxAgent_PTYKill_FullMethodName = "/agent.SandboxAgent/PTYKill"+ SandboxAgent_SetEnvs_FullMethodName = "/agent.SandboxAgent/SetEnvs"SandboxAgent_Shutdown_FullMethodName = "/agent.SandboxAgent/Shutdown"SandboxAgent_SyncFS_FullMethodName = "/agent.SandboxAgent/SyncFS")@@ -64,6 +65,10 @@ type SandboxAgentClient interface {PTYCreate(ctx context.Context, in *PTYCreateRequest, opts ...grpc.CallOption) (*PTYCreateResponse, error)PTYResize(ctx context.Context, in *PTYResizeRequest, opts ...grpc.CallOption) (*PTYResizeResponse, error)PTYKill(ctx context.Context, in *PTYKillRequest, opts ...grpc.CallOption) (*PTYKillResponse, error)+ // SetEnvs stores sandbox-level environment variables inside the agent.+ // These are injected into every subsequent Exec/ExecStream call,+ // between the base OS env and per-command envs.+ SetEnvs(ctx context.Context, in *SetEnvsRequest, opts ...grpc.CallOption) (*SetEnvsResponse, error)// Shutdown gracefully terminates the agent and syncs disks.Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error)// SyncFS flushes all filesystem buffers without exiting.@@ -228,6 +233,16 @@ func (c *sandboxAgentClient) PTYKill(ctx context.Context, in *PTYKillRequest, opreturn out, nil}+func (c *sandboxAgentClient) SetEnvs(ctx context.Context, in *SetEnvsRequest, opts ...grpc.CallOption) (*SetEnvsResponse, error) {+ cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)+ out := new(SetEnvsResponse)+ err := c.cc.Invoke(ctx, SandboxAgent_SetEnvs_FullMethodName, in, out, cOpts...)+ if err != nil {+ return nil, err+ }+ return out, nil+}+func (c *sandboxAgentClient) Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error) {cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)out := new(ShutdownResponse)@@ -275,6 +290,10 @@ type SandboxAgentServer interface {PTYCreate(context.Context, *PTYCreateRequest) (*PTYCreateResponse, error)PTYResize(context.Context, *PTYResizeRequest) (*PTYResizeResponse, error)PTYKill(context.Context, *PTYKillRequest) (*PTYKillResponse, error)+ // SetEnvs stores sandbox-level environment variables inside the agent.+ // These are injected into every subsequent Exec/ExecStream call,+ // between the base OS env and per-command envs.+ SetEnvs(context.Context, *SetEnvsRequest) (*SetEnvsResponse, error)// Shutdown gracefully terminates the agent and syncs disks.Shutdown(context.Context, *ShutdownRequest) (*ShutdownResponse, error)// SyncFS flushes all filesystem buffers without exiting.@@ -332,6 +351,9 @@ func (UnimplementedSandboxAgentServer) PTYResize(context.Context, *PTYResizeRequfunc (UnimplementedSandboxAgentServer) PTYKill(context.Context, *PTYKillRequest) (*PTYKillResponse, error) {return nil, status.Error(codes.Unimplemented, "method PTYKill not implemented")}+func (UnimplementedSandboxAgentServer) SetEnvs(context.Context, *SetEnvsRequest) (*SetEnvsResponse, error) {+ return nil, status.Error(codes.Unimplemented, "method SetEnvs not implemented")+}func (UnimplementedSandboxAgentServer) Shutdown(context.Context, *ShutdownRequest) (*ShutdownResponse, error) {return nil, status.Error(codes.Unimplemented, "method Shutdown not implemented")}@@ -604,6 +626,24 @@ func _SandboxAgent_PTYKill_Handler(srv interface{}, ctx context.Context, dec funreturn interceptor(ctx, in, info, handler)}+func _SandboxAgent_SetEnvs_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {+ in := new(SetEnvsRequest)+ if err := dec(in); err != nil {+ return nil, err+ }+ if interceptor == nil {+ return srv.(SandboxAgentServer).SetEnvs(ctx, in)+ }+ info := &grpc.UnaryServerInfo{+ Server: srv,+ FullMethod: SandboxAgent_SetEnvs_FullMethodName,+ }+ handler := func(ctx context.Context, req interface{}) (interface{}, error) {+ return srv.(SandboxAgentServer).SetEnvs(ctx, req.(*SetEnvsRequest))+ }+ return interceptor(ctx, in, info, handler)+}+func _SandboxAgent_Shutdown_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {in := new(ShutdownRequest)if err := dec(in); err != nil {@@ -699,6 +739,10 @@ var SandboxAgent_ServiceDesc = grpc.ServiceDesc{MethodName: "PTYKill",Handler: _SandboxAgent_PTYKill_Handler,},+ {+ MethodName: "SetEnvs",+ Handler: _SandboxAgent_SetEnvs_Handler,+ },{MethodName: "Shutdown",Handler: _SandboxAgent_Shutdown_Handler,