Costco is teaming up with delivery start-up Instacart to test free delivery of prescription drugs to members.

The pilot program is limited to California and Washington state, according to two people familiar, and it includes delivery to a Costco member's home or office. One Costco member who has used the service told CNBC that he received a text earlier this month to offer him the medication delivery option as an alternative to picking up the meds in store.

The move could help Costco compete with Amazon and Walmart, both of which have dabbled in prescription delivery. Amazon made its first steps into the space in 2018 by purchasing PillPack, an internet pharmacy start-up focusing on patients with chronic ailments, and Walmart offers mail-order delivery in some areas. The moves also pose a threat to large pharmacies like CVS and Walgreens. The pharmacy and drug space is valued at more than $300 billion and is expected to grow, making it an attractive market opportunity for the largest retailers.

Delivery will be free on orders that cost $35 or more, not including a tip, which Instacart sets at 5% of the order price. Otherwise, prices vary depending on how quickly a member needs the medicines delivered — the fastest option is an hour — but typically cost less than $10. Updates are provided via text message, which mirrors the experience of ordering groceries from Instacart.

Unlike Instacart's grocery delivery service, however, the Instacart delivery person will ask for proof of identity to ensure they're delivering to the right person, and the checkout process requires buyers to confirm their date of birth (the service is available only to people over age 18). There's also an option for a phone consultation from a Costco pharmacist.

Instacart workers will be allowed to deliver medications only if they pass a HIPAA certification training, meaning they're aware of the rules around managing people's sensitive health information.

Costco did not immediately return a request for comment. Instacart declined to offer a comment for this story.