We study stable constant mean curvature (CMC) hypersurfaces $$\Sigma $$ with free boundary in slabs in a product space $$M\times {\mathbb {R}},$$ where M is an orientable Riemannian manifold. We obtain a characterization of stable cylinders and prove that if $$\Sigma $$ is not a cylinder then it is locally a vertical graph. Moreover, in case M is $${\mathbb {H}}^n,{\mathbb {R}}^n$$ , or $${\mathbb {S}}_+^n,$$ if each component of $$\partial \Sigma $$ is embedded, then $$\Sigma $$ is rotationally invariant. When M has dimension 2 and Gaussian curvature bounded from below by a positive constant $$\kappa ,$$ we prove there is no stable CMC with free boundary connecting the boundary components of a slab of width $$l\ge 4\pi /\sqrt{3\kappa }.$$ We also show that a stable capillary surface of genus 0 in a warped product $$[0,l]\times _f M$$ where $$M={\mathbb {R}}^2, {\mathbb {H}}^2$$ , or $${\mathbb {S}}^2,$$ is rotationally invariant. Finally, we prove that a stable CMC immersion of a closed surface in $$M\times {\mathbb {S}}^1(r),$$ where M is a surface with Gaussian curvature bounded from below by a positive constant $$\kappa $$ and $${\mathbb {S}}^1(r)$$ the circle of radius r, lifts to $$M\times {\mathbb {R}}$$ provided $$r\ge 4/\sqrt{3\kappa }$$ .