Speaker Nancy Pelosi is heading into what could be one of the most challenging stretches of her long career with little room for error as her party attempts to put in place what President Biden is touting as a transformative agenda for the country.

House Democrats will return from a three-week recess Tuesday to a slimmer majority than when they left last month following the death of Rep. Alcee L. Hastings (Fla.) on Tuesday and two Democrats resigning to work in Biden’s Cabinet after they helped pass the $1.9 trillion pandemic relief bill.

Previously, Democrats could afford to lose only five votes, but as of next week, they can lose only two and still get any legislation passed without Republican support. While that number is expected to tick up as empty seats are filled throughout the summer, the Democratic House majority will remain razor thin.

As the House sets out to begin crafting Biden’s $2 trillion infrastructure bill, Pelosi (D-Calif.) and her leadership team will have to balance at times competing demands from the liberal and moderate wings of her caucus on spending for such things as highways, bridges, climate change and elder care. It is likely to be a trickier task than keeping her members united around a bill aimed at the devastation caused by a pandemic that has killed more than 550,000 Americans. And with only a few votes to play with, even a handful of dissenters could upend the party’s plans or force leaders to scale back their ambitions.

Pelosi’s supporters said she has the track record and skills to navigate the party’s legislative priorities through the narrow political straits in the months ahead. They note that as speaker she has helped usher into law sweeping legislation such as the Affordable Care Act and the Dodd-Frank banking law during the Obama administration and Biden’s $1.9 trillion stimulus bill earlier this year.

“She’s tried and battle tested. I would really caution you not to underestimate the skill of Nancy Pelosi,” said former congressman Joseph Crowley (D-N.Y.), a onetime member of Pelosi’s leadership team who lost his seat to Rep. Alexandria Ocasio-Cortez (D-N.Y.) in 2018.

But signs of the problems Pelosi could face with her slim majority are already emerging.

A group of eight Democrats representing mostly Northeastern districts recently declared they would vote against tax increases Biden has proposed to pay for his infrastructure proposal unless a cap on state and local tax (SALT) deductions included in President Donald Trump’s 2017 tax cut law is repealed. During a news conference last week, Pelosi said she was “sympathetic” to the group’s position as a representative of California, a state that has also strongly felt the impact of the SALT provision, and remains hopeful the issue can be addressed. She also made clear that she didn’t want members airing their concerns publicly.

“I would withhold any comment about whether you’re going to vote for a bill or not until you see what the bill is,” she said.

Meanwhile, some liberal members, including Ocasio-Cortez, have said Biden’s infrastructure package, which addresses a range of policy issues, needs to be more ambitious.

In a fundraising email sent to supporters Wednesday, Ocasio-Cortez’s team called the president’s proposal “a starting point,” saying that although it has “some key victories . . . one thing is for certain: It’s not enough.”

Speakers normally operate with a much larger majority than their counterparts in the Senate, giving them more control of the legislation that passes through the House. But Pelosi now finds herself in a position not too distant from Senate Majority Leader Charles E. Schumer (D-N.Y.), who oversees an evenly divided Senate where Vice President Harris provides the tiebreaking vote and individual senators such as moderates Joe Manchin III (D-W.Va.) and Kyrsten Sinema (D-Ariz.) can stall legislation.

Whereas during her previous tenure as speaker, Pelosi could afford to let a sizable group of her members vote against Democratic priorities that caused them political headaches, she doesn’t have that luxury now.

The devil of what could inflame tensions within the caucus will be in the details, which will soon be worked out by the committees overseeing aspects of Biden’s infrastructure proposal.

Liberals and moderates will fully delve into the legislative specifics upon their return from the recess next week, and both factions said they so far remain optimistic that they can create a package that includes an array of high-priority policies.

Senior Democratic aides also expressed confidence that internal divisions can be worked out, arguing that the infrastructure proposal, like the coronavirus relief bill, is proving popular with the public, providing an incentive for action not opposition.

“No one wants to prevent popular bills from being campaigned on,” said one aide who, like others, spoke on the condition of anonymity because they were not authorized to discuss internal deliberations.

Pelosi’s office expressed a similar level of confidence.

“The unifying factor for House Democrats is the shared mission to address the needs of hard-working families,” Drew Hammill, deputy chief of staff to Pelosi, said in a statement. “The Speaker continues to lead by consensus, not only in how we develop our agenda, but how we execute it moving forward. Doing so helps the Caucus forge the boldest common denominator as we work with the White House to build back better.”

Members across from the centrist and liberal wings of the party have mostly been careful to downplay any potential tensions. Liberals pointed out that most of their priorities made it into the final relief package, with the notable absence of raising the minimum wage, as evidence that the party has moved closer to their views, easing the disagreements with centrists that flared in the past.

“What people don’t realize is the progressives got a lot of our priorities,” said Rep. Ro Khanna (D-Calif.), a member of the Congressional Progressive Caucus. “I definitely don’t think [leadership] should take the progressive wing for granted, and I know they don’t because they know what happened in the negotiations” on the coronavirus relief plan.

Moderate Democrats have voiced concerns about continuing to cast votes on expensive legislative packages that could be used against them by Republican challengers in tight races next year. But two aides who work for swing-district members said it’s unlikely centrists would torpedo a key part of Biden’s agenda, particularly if it includes priorities for their districts, such as greater broadband availability or making the child tax credit in the stimulus permanent.

Rep. Susan Wild (D-Pa.), who flipped a GOP district in 2018, said she hopes the infrastructure bill includes provisions that would lower the cost of prescription drugs, an issue her constituents in eastern Pennsylvania have been pushing for since before the pandemic.

“First and foremost, we’ve got to get the traditional infrastructure piece of this — roads, bridges, broadband, water — that are essential. Do I think it makes sense from where we are as a country to put in other priorities that we have and see how it all shakes out? Yes,” she said. “Do I think that these priorities should be dealbreakers? No.”

If disagreements emerge, Crowley said Pelosi’s ability to massage differences is based on her knowledge of what members need to hold on to their seats.

“I think Nancy is a progressive’s progressive, and at the same time she recognizes that in order to have the bully pulpit or in order for Democrats to be in the majority, we also have to focus on the needs of those moderate members, moderate districts that send those people to the House of Representatives to keep the majority,” he said.

Asked last month whether Democrats should take a more narrow approach to crafting an infrastructure bill that would be easier for the Senate to pass or go bold, Pelosi leaned toward bold.

“Just if you promise not to tell anybody I said this, one of the challenges we face — and you’ve heard me say this — is we cannot just settle for what we can agree on without recognizing this has to be a bill for the future,” she said during a news conference. “We have to strike the balance because we would be wasting our time to build or create legislation that is of the past century instead of going forward into the future.”