General manager Bobby Evans confirmed the deal Thursday. Cabrera is scheduled to join San Francisco's Arizona rookie league team initially then move on to Triple-A Sacramento when ready, Evans said.
The 28-year-old Cabrera appeared in 29 games for Baltimore this season, batting .208 with a pair of doubles and four RBIs before his release last month.
He spent the previous six seasons in the National League West with San Diego regularly facing the reigning World Series champion Giants, who also won titles in 2010 and 2012.
Cabrera was suspended by Major League Baseball for the final 50 games of the 2013 season for violating the sport's drug agreement in relation to its Biogenesis of America investigation.