Is outlet box required to be mounted?
"Wire", eh?  Romex NM/UF/SE/MH/whatever multiconductor building cable is out of the question. It's not flexible, and is made for immobile use in protected locations, like behind walls, rafters, underground or in conduit. You can't use building cable for flexible cord at all. 

Even if you have proper cordage, you're not allowed to homebrew extension cords with a handi-box and some cord.  Specifically, 400.8 disallows any flexible cords


  
  Used as substitutes for the fixed wiring of a structure.
  Run through holes in walls, structural ceilings, suspended or dropped ceilings, or floors.
  Run through doorways, windows, or similar openings.
  Attached to building surfaces.
  Concealed by walls, floors, or ceilings — or located above suspended or dropped ceilings.
  Installed in raceways, except as permitted elsewhere in the NEC.
  Used or installed in a manner that unduly exposes them to physical damage.
  


400.7 carves out exceptions where you are allowed to use flexible cords: 


  
  Pendants [210.50(A) and 314.23(H)] if the cords are identified for pendant use in Table 400.4.
  Wiring of luminaires as allowed by 410.24(A) and 410.62(B).
  Connection of portable luminaires, portable and mobile signs, or appliances as allowed in 422.16 [400.7(A)(3), but when used with attachment plugs [400.7(B)].
  Elevator cables.
  Wiring of cranes and hoists.
  Connection of utilization equipment to facilitate frequent interchange [422.16], but only when used with attachment plugs [400.7(B)].
  Prevention of the transmission of noise or vibration [422.16].
  Appliances where the fastening means and mechanical connections are specifically designed to permit ready removal for maintenance and repair, and the appliance is intended or identified for flexible cord connections [422.16], but only when used with attachment plugs [400.7(B)].
  Connection of moving parts.
  Where specifically permitted elsewhere in the NEC.