We establish, in a rather general setting, an analogue of DiPerna-Lions theory on wellposedness of flows of ODE's associated to Sobolev vector fields. Key results are a wellposedness result for the continuity equation associated to suitably defined Sobolev vector fields, via a commutator estimate, and an abstract superposition principle in (possibly extended) metric measure spaces, via an embedding into R ∞ . When specialized to the setting of Euclidean or infinite dimensional (e.g. Gaussian) spaces, large parts of previously known results are recovered at once. Moreover, the class of RCD(K, ∞) metric measure spaces introduced in [AGS14b] and object of extensive recent research fits into our framework. Therefore we provide, for the first time, wellposedness results for ODE's under low regularity assumptions on the velocity and in a nonsmooth context.