Cooperation is fundamental to many biological systems. A common metaphor for studying the evolution of cooperation is the Prisoner's Dilemma, a game with two strategies: cooperate or defect. However, cooperation is rare all or nothing, and its evolution probably involves the gradual extension of initially modest degrees of assistance. The inability of the Prisoner's Dilemma to capture this basic aspect limits its use for understanding the evolutionary origins of cooperation. Here we consider a framework for cooperation based on the concept of investment: an act which is costly, but which benefits other individuals, where the cost and benefit depend on the level of investment made. In the resulting Continuous Prisoner's Dilemma the essential problem of cooperation remains: in the absence of any additional structure non-zero levels of investment cannot evolve. However, if investments are considered in a spatially structured context, selfish individuals who make arbitrarily low investments can be invaded by higher-investing mutants. This results in the mean level of investment evolving to significant levels, where it is maintained indefinitely. This approach provides a natural solution to the fundamental problem of how cooperation gradually increases from a non-cooperative state.