The Stallings construction for finitely generated subgroups of free groups is generalized by introducing the concept of Stallings section, which allows an eficient computation of the core of a Schreier graph based on edge folding. It is proved that those groups admitting Stallings sections are precisely finitely generated virtually free groups, through a constructive approach based on Bass-Serre theory. Complexity issues and applications are also discussed.