Metal Sandbox: Isolated Execution and Command Scheduling for GPU Coding Agents on Apple Silicon

Haozhe Wang, Lina Chen, Fanqi Wan, Qi Han, Yinmin Zhang, Zheng Ge, Daxin Jiang, Junchi YanarXiv 2026

TL;DR

Metal Sandbox is a new infrastructure designed to accelerate the training and evaluation of LLM agents that generate Apple Metal GPU kernels. By combining per-instance filesystem isolation with a smart, cross-node command scheduler, it achieves over 2x gains in sustained throughput and significantly reduces idle time during agent rollouts.

What Problem Does This Paper Address?

As on-device AI becomes more prevalent, there is a growing need for highly optimized GPU kernels tailored for Apple Silicon (M-series and A-series chips). While Large Language Models (LLMs) are increasingly capable of generating these kernels, they require a native environment for iterative testing, compilation, and performance profiling.

However, setting up such an environment presents two major challenges:

  1. Isolation: Running untrusted, model-generated code directly on a host machine is risky. Traditional containerization like Docker often struggles with native macOS tools or lacks direct, low-overhead access to Apple’s GPU APIs.
  2. Efficiency: Interactive agent sessions are surprisingly "bursty." As shown in Figure 1, a typical session might spend less than 3% of its time actually executing code on the GPU. The rest is spent on model reasoning, file editing, or CPU-bound preparation. In a naive setup, this leaves expensive hardware sitting idle most of the time.
Figure 1. One metal_nbody agent session without competing sessions. GPU activity totals 44.0 seconds (2.32%) over 31.6 minutes. Agent phases and GPU activity share the session timeline. The GPU curve is the active fraction of each one-second window; its area gives the total active time. Gray denotes activity outside the recorded model and tool phases.

Methods

The authors introduce Metal Sandbox, which leverages native macOS features to create a high-performance, secure, and distributed execution environment.

  • Native Isolation: Instead of heavy virtual machines, the system uses Apple’s App Sandbox to restrict file access on a per-instance basis. Each agent gets its own workspace and private HOME directory, preventing it from interfering with the host system or other agents.
  • Command-Level Scheduling: Rather than scheduling entire agent sessions, Metal Sandbox schedules individual commands. It uses an "allowlist" to identify parallelizable tasks (like ls, mkdir, or compilers) that can run concurrently. GPU-intensive or timing-sensitive commands are sent to a serial FIFO queue (one per node) to ensure clean performance measurements.
  • Cross-Node Migration: To balance the load across a cluster of Macs, the system implements a reservation-claim-commit protocol. If one Mac is swamped with serial commands while another is idle, the controller can migrate a waiting command to the idle node, execute it using shared storage (SMB), and return the results to the original agent.
Figure 2. Command scheduling and execution. Allowlist matches receive parallel execution permissions; other commands enter the node’s serial FIFO queue. Both paths execute native commands in an App Sandbox process, and Metal calls submit work to the Apple GPU. GPU timing commands use the serial path under the configured rules. Eligible waiting commands can migrate through target-node reservation, claim, and commit, using shared instance files. Outputs return to the original tool call.

Datasets

The system was evaluated using the Harbor orchestration framework. The primary task used for testing was metal_nbody, which requires an agent to implement a native Metal gravitational simulation, including a renderer and a benchmark entry point.

For evaluation, the authors collected sixteen static agent traces using mini-SWE-agent powered by the Step 5 Preview model. These traces provided a realistic baseline of how coding agents interact with the system over long durations (averaging ~45 minutes per session).

Key Insights and Ideas

  • The "Idle GPU" Opportunity: The most striking insight is the extreme underutilization of the GPU in interactive sessions. By treating GPU execution as a scarce resource to be scheduled independently of the agent's reasoning phases, the authors unlocked massive throughput gains.
  • Command-Level vs. Session-Level: Most distributed systems for agents focus on placing the entire agent on a node. Metal Sandbox proves that for GPU tasks, moving the work to the data (or in this case, the idle accelerator) is more efficient.
  • Native is Better: By avoiding the "Linux-in-a-VM" overhead typical of Docker on Mac, the system provides agents with the exact same toolchain (compilers, SDKs) used by human developers, ensuring that generated kernels are truly optimized for the target hardware.

Key Results

The authors tested Metal Sandbox on a cluster of four Mac mini M4 nodes (Figure 3).

Figure 3. Four-Mac deployment. Harbor and the cluster controller run on Mac mini #A, which also executes work. Solid arrows show SSH control requests; the dashed arrow shows command migration from #B’s waiting queue to #D. CPU/GPU arrows show parallel preparation and serial Metal execution. The agent stays on its owner Mac. All nodes have network access and prepared SMB workspace/HOME paths.
  • Throughput Gains: Under concentrated demand, the system achieved 1.68× to 2.05× gains in command throughput compared to static scheduling.
  • Sustained Performance: For a scenario with four sessions per node, the authors estimate a 2.14× sustained-throughput gain over a single-session-per-node setup.
  • Reduced Latency: Replaying real-world agent traces under dynamic scheduling reduced the mean time agents spent waiting for tools by 18.8% and cut the total batch elapsed time by 22.3%.

Limitations and Future Work

While highly effective, the authors note several limitations:

  • Security Boundaries: The App Sandbox provides good isolation for ordinary development, but it is not designed for "hostile" multi-tenant environments. Some application-launch paths might still fall outside the sandbox's reach.
  • GPU Exclusivity: The system serializes commands to ensure clean timing, but it doesn't provide physical hardware-level exclusivity. Other background macOS processes could still theoretically interfere with GPU performance.
  • Static Replay Assumptions: The trace-driven replay assumes that agent behavior (the sequence of commands) wouldn't change if the tools responded faster. In reality, faster feedback might lead to different, potentially more efficient, agent trajectories.

Metal Sandbox is open-source and available on GitHub, providing a robust foundation for anyone looking to scale LLM-based GPU kernel development on Apple hardware.

Summary updated

Abstract

On-device inference requires kernels that make effective use of local accelerators. Efficient training and evaluation of models that generate Apple Metal kernels benefit from native macOS tools and concurrent agent sessions. These sessions alternate between model requests, development commands, and GPU execution, leaving GPU capacity idle for much of a rollout. We present Metal Sandbox, infrastructure that combines restricted per-instance file access, native command execution, and command-level scheduling across interconnected Macs. Each agent retains its workspace and private development environment. Parallel commands can run concurrently, while serial commands share one execution slot per node; eligible waiting commands can migrate to available Macs and return results to the original agent. Integration with Harbor supports task execution, automatic verification, and rollout collection through a common workflow. Controlled experiments on four Mac mini M4 nodes achieve $1.68\times$--$2.05\times$ gains in command throughput under concentrated demand. Sixteen static agent traces give an estimated $2.14\times$ sustained-throughput gain for four sessions per node versus one, assuming continuously replenished sessions and unchanged mean durations. Replaying these measured traces under dynamic scheduling reduces mean tool waiting by 18.8% and batch elapsed time by 22.3%, assuming unchanged phase durations. Metal Sandbox and its Harbor integration are open-source on GitHub.
BibTeX
@misc{wang2026metal,
  author = {Haozhe Wang and Lina Chen and Fanqi Wan and Qi Han and Yinmin Zhang and Zheng Ge and Daxin Jiang and Junchi Yan},
  title = {{Metal Sandbox: Isolated Execution and Command Scheduling for GPU Coding Agents on Apple Silicon}},
  year = {2026},
  eprint = {2611.17294},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.17294},
}
Figure