This summary from UrbanAgLaw.org (formerly run by the Sustainable Economies Law Center, but no longer updated) gives a summary of the US federal laws:
Traditionally, the FDA has been concerned primarily with fruits & vegetables that travel in interstate commerce (i.e., fruits and vegetables that are sold and/or transported across state lines); however, FDA authority has been greatly expanded through the Bioterrorism Act of 2002 and the Food Safety Modernization Act (FSMA) of 2011. ...
The good news is that these new requirements do not apply to most urban farming operations. And the FSMA provides exemptions from most of its requirements to farms with: (1) less than $500,000 in annual gross sales; and (2) more than half of the product sold to “qualified end users,” defined as consumers and restaurants or retailers (not including wholesalers or distributors) either in-state or within 275 miles of the farm or facility. ...
The FDA also shares some of the health and safety regulation of fruits and vegetables with the Federal Environmental Protection Agency (EPA). The EPA is authorized (under the Federal Food, Drug, and Cosmetics Act) to set tolerance levels for pesticides on and in foods. While regulatory testing of the pesticide levels on unprocessed fruits and vegetables is unlikely, it is a good practice (for obvious reasons) to limit pesticide use as much as possible, and to limit pesticide residues by thoroughly washing produce.
State and local regulations may also apply; the guide recommends that you contact local health department officials and/or your state university's agricultural extension program (if one exists) to find more specific information:
While state food codes are primarily focused on health and safety surrounding retail sales of food products, other state food and agriculture laws may focus more on health and safety matters surrounding production, shipping, handling, storage, and processing of food products. These activities may be addressed in state food codes, health codes, agriculture codes, etc., and permits and licenses may be required for these activities. Furthermore, state and local regulatory officials often make judgment calls in deciding whether these licensing and/or permit requirements apply to a particular operation. Therefore, whatever your urban farming activity, it is important that you seek guidance from your state and local agriculture and health department (e.g., visit the website, write to a local health department official) to see what licensing and permit requirements apply.