As mentioned in class, the system with an ideal gas and a vacuum will have a constant temperature becasue the energy that it loses when it is doing work is replaced by the heat of the surroundings going into the system. Does the heat coming into the system (q) come in for the purpose of maintaining a constant temperature, or is there another reason for which the heat enters the system?

I'm still having a bit of a hard time wrapping my head around how the temperature of the system can stay constant if heat is entering from its surroundings. What is the heat reservoir that the surrounding heat goes to? Thanks in advance!