In spin-based electronics, information is encoded by the spin state of electron bunches 1,2,3,4 . Processing this information requires the controlled transport of spin angular momentum through a solid 5,6 , preferably at frequencies reaching the so far unexplored terahertz (THz) regime 7,8,9 . Here, we demonstrate, by experiment and theory, that the temporal shape of femtosecond spin-current bursts can be manipulated by using specifically designed magnetic heterostructures. A laser pulse is employed to drive spins 10,11,12 from a ferromagnetic Fe thin film into a nonmagnetic cap layer that has either low (Ru) or high (Au) electron mobility. The resulting transient spin current is detected by means of an ultrafast, contactless amperemeter 13 based on the inverse spin Hall effect 14,15 that converts the spin flow into a THz electromagnetic pulse. We find that the Ru cap layer yields a considerably longer spin-current pulse because electrons are injected in Ru d states that have a much smaller mobility than Au sp states 16 . Thus, spin current pulses and the resulting THz transients can be shaped by tailoring magnetic heterostructures, which opens the door for engineering high-speed spintronic devices as well as broadband THz emitters 7,8,9 , in particular covering the elusive range from 5 to 10THz.Contemporary electronics is based on the electron charge as information carrier whose presence or absence encodes the value of a bit. Much more efficient devices for low-power data storage and processing could be realized if the spin degree of freedom were used in addition 1,2,3,4 . The spintronics approach requires the generation and control of spin currents, that is, the transport of spin angular momentum through space 5,6 . Spintronic operations should be performed at a pace exceeding that of today's computers, which ultimately requires the generation of spin current pulses with terahertz (1 THz = 10 12 Hz) bandwidths 7,8 as well as the possibility to manipulate them in novel structures 17,18 . To date, femtosecond spin-current pulses have been successfully launched by optically exciting electrons in semiconductors 10 or ferromagnetic metals 11,12 . However, to enable ultrafast basic operations on these transients (such as buffering or delaying), their shape and propagation have to be controlled on subpicosecond time scales.Here, we employ magnetic heterostructures containing an optimally chosen nonmagnetic metallic layer whose electron mobility allows us either to trap or to transmit electrons and, thus, to engineer ultrafast spin pulses. The spin flow is probed in a contactless manner using the inverse spin Hall effect 14,15 (ISHE) that converts the spin current into a detectable THz electromagnetic pulse 13 . Our findings open up a route to device-oriented femtosecond spintronics as well as novel broadband emitters of THz radiation 7,8,9 .Our idea is illustrated in Fig. 1a, which shows a schematic of a ferromagnetic Fe film capped by a thin layer of Ru or Au. Absorption of a femtosecond laser pulse (photon energy 1...