Many materials-processing applications such as crystal growth from the melt involve thermocapillary flows that can affect the quality of the final product, particularly under microgravity conditions where the influence of buoyancy-driven convection is minimized. When the melt contains volatile components, as in the production of III-V semiconductor crystals, it is often encapsulated in a low-melting point amorphous molten glass phase such as boron oxide or pyrolytic boron nitride in order to prevent evaporation of the volatile components. The addition of the encapsulant layer and the melt-encapsulant interface in such cases can alter the thermocapillary flow in the melt. In this study, thermocapillary convection within a differentially heated rectangular cavity containing two immiscible liquid layers is considered in the absence of gravity. Domain mapping is used in conjunction with a finite difference scheme on a staggered grid to solve for the temperature and flow fields. The melt encapsulant and the air-encapsulant interfaces are allowed to deform, with the contact lines pinned on the solid boundaries. The computed flow fields are compared to the corresponding results for a cavity with a rigid top surface. The presence of a free surface at the top leads to increased convection in the encapsulant phase while suppressing the thermocapillary flow in the melt phase. The flow pattern in the encapsulated layer is strongly dependent on the viscosity of the encapsulant layer. The intensity of the thermocapillary flow within the melt is significantly reduced as the viscosity of the encapsulant layer is increased. However, for a higher encapsulant viscosity, the retarding effect of the free top surface on thermocapillary convection in the melt is weakened.