Hydrophobic confinement modulates thermal stability and assists knotting in the folding of tangled proteins.