The sorption-based atmospheric water harvesting technique is an appealing solution for addressing the challenge of freshwater shortages. In this study, a composite foam was fabricated by confining hygroscopic salt (CaCl2) into a Cr-based metal–organic framework (MIL-101), which was then integrated into a bacterial cellulose (BC) skeleton. The hierarchical structure, which contains micron- and nanoscale pores, enhances water storage, transport, and vapor evaporation throughout the whole water capture and release process. The pore confinement effect of MIL-101 and the interconnected BC network effectively restricted the leakage of the liquefied salt solution. Interestingly, the color of the CaCl2@MIL-101@BC foam changed from light green to dark green as the amount of absorbed water increased. This moisture-induced color darkening improves the light absorption ability during the water release stage under sunlight. At 30 % relative humidity, the foam can absorb up to 0.78 g g−1 of water per cycle (8 h) and desorb quickly under solar radiation. This makes foam a promising method for water production in arid areas.