What you could do is:
- employed by foreign company
- visit US for MEETINGS with colleagues at a US firm - come up with an agenda (of course you can code during your month here)
- your work cannot be directly FOR a US firm
- the US firm cannot pay you a wage/salary
- the US firm can reimburse your foreign employer for travel/accommodation to/from/in the US, who in turn would presumably cover your expenses while here.
The operative word is "meeting" as opposed to sitting in a cubicle and cranking out code.
What I outlined above is a very common occurrence. Many companies have foreign staff (or staff from foreign associated companies / partners) come in for business meetings.
*edit: i don't know if anyone else is reading this thread, but references for a trustworthy lawyer who can discuss a specific situation via email would be welcome.