A Prym construction for the cohomology of a cubic hypersurface. Extending the Prym map to toroidal compactifications of the moduli space of abelian varieties (with an appendix by Mathieu Dutour Sikirić) 