The goal of this paper is to provide a categorical framework that leads to the definition of shtukas à la Drinfeld and of excursion operators à la V. Lafforgue. We take as the point of departure the Hecke action of Rep( Ǧ) on the category Shv(BunG) of sheaves on BunG, and also the end-functor of the latter category, given by the action of the geometric Frobenius. The shtuka construction will be obtained by applying (various versions of) categorical trace.