In late July of this year, a problem with Apple's 2013 MacBook Air became apparent, where owners began experiencing intermittent black screens somewhat randomly when using their systems.
Since the initial reports of this problem, Apple has issued both general OS updates and upgrades with the release of Mavericks, as well as a specific graphics update for the 2013 MacBook Air; however, this problem has not yet been fixed and affected MacBook Airs continue to show random black screens.
The problem usually happens when systems are moved, bumped, or sometimes even slightly vibrated (such as might happen when typing vigorously), where it appears a sensor that activates sleep mode is triggered, causing a dimming of the display. In some instances the display will dim only briefly, other times it will dim for a number of seconds and result in the user having to enter his or her password when waking from sleep. Affected users have noted the prevalence of the problem increases, or only occurs, when the systems are using battery power instead of AC power.
While Apple has replaced some affected systems, it has not yet acknowledged the issue or offered an official repair or replacement plan for affected machines. It has been over six months since this problem was first found, so for those affected it may be best to take the system into an Apple Store for repair or replacement, especially if it's still covered by warranty or AppleCare.
Because the problem occurs primarily when on battery power, the only known workaround is to use the system on AC power as often as possible. The problem appears to only trigger sleep mode briefly, and while annoying, it does not seem to affect data, settings, or other system features.
Alternatives you can try (though not guaranteed to work) are third-party solutions such as this Google Code extension project that allows you to keep your MacBook awake even when the screen is closed.