We study the black hole thermodynamics in the presence of a string cloud matter distribution, considering a work term due to a variable cosmological "constant" in arbitrary dimensions. Then, we explore the criticality of the system and the behavior of the black hole as a heat engine in the context of general relativity and metric f (R) gravity.