(Andrew Harrer/Bloomberg)

Airbnb has reached a voluntary agreement with the state of New York in its months-long legal battle over housing rights. And from the looks of it, New York Attorney General Eric Schneiderman is getting pretty much everything he wanted from the company.

Here's the key idea behind the agreement: Airbnb will hand over data to the government on its New York hosts that's been stripped of personally identifiable information such as names, addresses, phone numbers and tax information. The anonymized data will protect the privacy of individual hosts. But there's a catch. The state attorney general can browse that data for possible lawbreakers and then go back to Airbnb for the actual, non-anonymized data on individual people. Airbnb will also inform its New York hosts about the state's Multiple Dwelling Law so that they know the rules.

The agreement "appropriately balances Attorney General Schneiderman’s commitment to protecting New York’s residents and tourists from illegal hotels with Airbnb’s concerns about the privacy of thousands of other hosts," the two parties said in a joint statement.

The deal puts an end to a long-simmering disagreement between the two parties concerning Airbnb hosts who may be running "illegal hotels." Basically, if you're renting out your apartment for less than 30 days and you aren't physically there with your guest, you're at risk of violating the state's Multiple Dwelling Law, according to the state attorney general.

"We are going to pursue anyone who's running illegal hotels," Schneiderman told reporters Wednesday. "We view this as a template for other places in the country where the issue has been raised."

Last week, Airbnb successfully managed to quash Schneiderman's subpoena for its data on the grounds that it was too broad. But the judge who tossed it out, Gerald Connolly, found that "a substantial number of hosts" may be breaking state law. His decision effectively told the New York attorney general's office how to rewrite the subpoena to be acceptable. Under those circumstances, Airbnb lacked compelling options. It could either go to court and lose, or comply with the subpoena and seek caveats.

As a result, Airbnb won't be forced to hand over unredacted data on all 15,000 hosts in the state. From a privacy standpoint, that's a win for the company (and for ordinary hosts who may have done nothing illegal). But, overall,  Schneiderman will still be free to use the Multiple Dwelling Law to pursue whomever he suspects of running afoul of the rules, which Airbnb says is the real problem.

"The law that made this investigation possible is still on the books," wrote David Hantman, Airbnb's head of public policy, in a blog post. "And we need to change that law to allow anyone in New York who wants to rent out their own home to do so."

This is probably where a lot of sharing-economy companies may be headed. As more firms like Airbnb, Uber and Aereo rub up against existing systems of law and regulation, the debate will not be whether to hand over data, but how to do it and under what limitations.