Managed code is code whose execution is overseen by a runtime rather than run directly by the operating system. Microsoft puts it plainly: “managed code is just that: code whose execution is managed by a runtime,” and on .NET that runtime is the Common Language Runtime. The runtime takes the program, compiles it to machine code, and then runs it, while also providing “several important services such as automatic memory management, security boundaries, and type safety.”
The contrast is with “unmanaged code,” the traditional way a C or C++ program runs. Microsoft describes the unmanaged world as one where “the programmer is in charge of pretty much everything”: the program is a binary that the operating system loads and starts, and “everything else, from memory management to security considerations, are a burden of the programmer.” Managed runtimes lift much of that burden by tracking objects, reclaiming memory through garbage collection, and refusing operations that would violate type safety.
Managed code does not usually compile straight to machine instructions. A .NET language compiler produces Intermediate Language instead, and the runtime just-in-time compiles that to native code when the program runs. The same idea underlies the Java Virtual Machine, which executes Java bytecode: in both systems an intermediate, portable form sits between the source language and the processor, letting the runtime supervise execution.
The boundary between managed and unmanaged worlds can be crossed. Microsoft notes that the CLR supports interoperability, allowing managed code to call into unmanaged libraries, and that C# even permits unmanaged constructs like raw pointers inside a designated “unsafe context” whose execution is not managed by the runtime. Managed code is therefore a default discipline rather than an absolute wall, the foundation of platforms like .NET and the JVM while still allowing escape hatches to native code when needed.