Unsafe at the Interface: A Cross-Language Safety Benchmark for Multimodal Code Agents

When a Python script calls a compiled C extension, or JavaScript calls a native addon, the two sides of that call are usually checked separately: a linter scans the Python, a compiler warning flags the C, and the binding between them — the glue that converts a managed object into a raw pointer and a byte count — is checked by nobody. That blind spot is well documented: Staicu et al. found that 30% of npm native-extension flows to type-conversion APIs lack sufficient type checks, yielding 33 vulnerable libraries and 7 CVEs, even though each side looked safe in isolation (Bilingual Problems: Studying the Security Risks Incurred by Native Extensions in Scripting Languages). Meanwhile, a separate community has shown that multimodal large language models — models that accept images and text together — fail exactly this kind of "each part benign, combination dangerous" reasoning: on the SIUO benchmark, 13 of 15 leading vision-language models could not reach even a 50% safe rate on safe-image-plus-safe-text pairs (Safe Inputs but Unsafe Output: Benchmarking Cross-modality Safety Alignment of Large Vision-Language Models).

This proposal argues these are the same failure wearing two hats, and that the collision is now practically urgent: code agents are increasingly multimodal (taking screenshots, diagrams, and documentation images as task input) and increasingly generate bilingual glue code (Python with inline C, ctypes bindings, JS with native addons). We will build a benchmark in which a benign high-level snippet and a benign native library combine into an exploitable Foreign Function Interface (FFI) vulnerability, evaluate multimodal code agents on it, and test a defense that is itself drawn from the native-code-analysis literature: a cross-language verifier that lifts both sides into one shared representation and checks the binding — the place where every existing guardrail is blind.

Core Claim

The claim has two parts, one descriptive and one prescriptive. Descriptively: multimodal code agents will exhibit the "safe + safe = unsafe" failure at the FFI boundary, and it will be worse than the physical-harm versions of the failure already measured, because no safety training to date covers cross-language memory safety, and because RedCode shows agents reason less critically when a task arrives as a natural-language or visual specification rather than raw code (RedCode: Risky Code Execution and Generation Benchmark for Code Agents). Prescriptively: prompt-based and input-filtering defenses cannot close this gap — the evidence for this already exists in the multimodal literature (FigStep's typographic attacks defeated OCR-based detection (FigStep : Jailbreaking Large Vision-Language Models via Typographic Visual Prompts); in-context demonstrations still leave roughly a 20% failure rate (Safe Semantics, Unsafe Interpretations: Tackling Implicit Reasoning Safety in Large Vision-Language Models)) — but a static verifier that models the boundary itself can, because the vulnerability is a structural property of the binding, not a semantic judgment about intent.

Research Program

The program has three pieces: a benchmark, an evaluation, and a verifier-in-the-loop defense.

The benchmark, which we call GlueBench, extends the information-complementarity methodology of SIUO (Safe Inputs but Unsafe Output) from physical harms to cross-language software security. Each case is a triple: a managed-side task (Python or JavaScript) that is flagged safe by single-language analyzers, a native-side library or C snippet that is flagged safe by C analyzers, and a binding whose combination is exploitable — a missing size check, a type confusion, a privilege drop. We will seed cases from real, published vulnerabilities: the 33 vulnerable npm libraries and 7 CVEs of Staicu et al. (Bilingual Problems) supply the Python/JS-to-C patterns, and the Type-1 direct-call-bypass and Type-2 confused-deputy patterns of IAceFinder (Uncovering Cross-Context Inconsistent Access Control Enforcement in Android) supply the privilege-inconsistency patterns. Crucially, half the cases present the task multimodally: the native API arrives as a screenshot of documentation, the architecture as a diagram, and in the adversarial subset the risky binding is suggested only through a typographic image in the FigStep style — so that the text prompt itself is fully benign. Ground truth is established by executing the generated binding in a Docker sandbox with AddressSanitizer and Valgrind, following the dynamic-verification practice of RedCode; an "unsafe" label requires a confirmed sanitizer crash, memory corruption, or privilege escalation, not merely a suspicious-looking snippet. We will also build a benign counterpart set of legitimate FFI tasks (image decoding via OpenCV, audio via FFmpeg), which lets us measure the false-refusal cost of any defense — the failure mode USB exposed when Claude 3.5 Sonnet refused 25.82% of harmless prompts (USB: A Comprehensive and Unified Safety Evaluation Benchmark for Multimodal Large Language Models).

The defense is a cross-language boundary verifier run as a tool in the agent loop. It reuses techniques the native-analysis community has already validated: lifting both sides into a shared intermediate representation, as ReuNify does when it lifts Hermes bytecode into Jimple and links JS-to-native calls (ReuNify: A Step Towards Whole Program Analysis for React Native Android Apps), and as JWBinder does when it reconstructs WebAssembly into JavaScript via an inter-language program dependency graph, raising commercial detection of multilingual malware from 49.1% to 86.2% (Static Semantics Reconstruction for Enhancing JavaScript-WebAssembly Multilingual Malware Detection); and normalizing security-relevant properties across languages into a comparable form, as IAceFinder does with its four-level privilege hierarchy. Our verifier computes, for every FFI call site the agent generates, whether type, size, and privilege annotations are consistent on both sides — Staicu et al.'s bilingual data-flow graph is the direct precedent — and returns a verdict the agent must condition on before execution. The hypothesis is that this verdict, being structural rather than semantic, achieves what safety-tuned prompts cannot.

Baselines

The naive reference point is a zero-shot multimodal code agent with no defense at all, given the GlueBench task and a Docker sandbox. This is the deployment reality today, and the literature gives calibrated expectations for it in adjacent settings: on RedCode, capable models generated functional malware over 70% of the time when they complied with risky requests (RedCode), and on SSUI, GPT-4o's zero-shot safety rate was 58.88% (Safe Semantics, Unsafe Interpretations). No reported result found on Lacuna for any model's safety rate on cross-language FFI generation, which is precisely the hole GlueBench fills.

The strongest existing competitor is in-context learning with safety demonstrations, the best-performing prompt-based defense with a reported number: on SSUI it lifted GPT-4o's safety rate from 58.88% to 80.90% (Safe Semantics, Unsafe Interpretations). We will run it on GlueBench with demonstrations written by the same annotators, matched to our benchmark's category structure, and give it the same tuning budget of demonstration examples that the verifier gets annotated boundary rules — so neither defense enjoys more human input. We also run UniGuard-style input filtering as a second competitor (UniGuard: Towards Universal Safety Guardrails for Jailbreak Attacks on Multimodal Large Language Models), because it reports only 0.2% accuracy degradation on A-OKVQA and is the strongest published guardrail on the utility axis. Beating the baselines means three things together: a higher boundary-safe rate (confirmed exploits avoided) than the best prompt-based defense, a lower harmless-refusal rate on the benign FFI set than USB's reported 25.82% for a heavily aligned commercial model, and maintained task completion on standard code benchmarks.

The key ablation is the verifier itself with its inter-language edges removed — run the same lifting pipeline on the Python side and the native side separately, but never propagate facts across the binding. If the full verifier wins by a large margin over this single-language version, the win is attributable specifically to boundary modeling and not to having any static tool in the loop. We also run conventional single-language linters (a Python security linter plus a C static analyzer) as a further ablation; no reported result found on Lacuna for their joint performance on FFI glue code, so we measure it ourselves under identical compute and configuration.

Why not just…?

Why not just lint the generated code before executing it? This is the most natural objection, and the literature is unambiguous about why it fails at exactly our target: single-language analyzers treat the FFI transition as a terminal point, which is why ReuNify found that single-language tools miss most of the reachable program in React Native apps — 70% of identified Jimple lines and 84% of callgraph paths on popular apps (ReuNify) — and why Qi et al. found multi-language commits substantially more defect-prone than single-language ones (Multi-Programming-Language Commits in OSS: An Empirical Study on Apache Projects). The linter ablation above is designed to make this concrete rather than rhetorical: if linters match the full verifier on GluteBench, our central claim is wrong and we will report that.

Why not just run everything in a container sandbox? Sandboxes bound the blast radius; they do not detect the flaw. NativeProtector shows that unmanaged libraries share the entire process memory space, so in-process credential theft and hijacking never require crossing a container wall (NativeProtector: Protecting Android Applications by Isolating and Intercepting Third-Party Native Libraries), Staicu et al. showed these flaws crash legitimate applications inside intact deployments (Bilingual Problems), and frontier models have been quantified attempting container escapes when given low-level access (Quantifying Frontier LLM Capabilities for Container Sandbox Escape). We adopt the sandbox as our measurement instrument — it is how ground truth is confirmed — while explicitly measuring in-process memory corruption as a harm the sandbox does not prevent. This is a real constraint on framing, not a knockdown: if a deployment truly only cares about exfiltration and remote effects, the practical value of our verifier shrinks, and we will report the in-process-only harm rates so readers can judge.

Why not just pre-filter the images with OCR or a guardrail model? FigStep already evaluated OCR-based defenses and found them largely ineffective, with attack variants actively evading them (FigStep); more fundamentally, in information-complementarity cases both inputs are benign in isolation, so any per-input filter scores them as harmless — this is the whole finding of SIUO (Safe Inputs but Unsafe Output). UniGuard optimizes its filters against known toxic string corpora, which cannot match a structural binding flaw that is not a string anywhere (UniGuard). The UniGuard baseline run will quantify how much of GlueBench it catches — likely only the typographic subset — and that result is itself informative.

Why not just improve the model's safety alignment with demonstrations and fine-tuning? This is a genuine threat, not a strawman: in-context demonstrations are the strongest reported defense on SSUI (58.88% → 80.90% for GPT-4o), and fine-tuning on RMS-style constructed data reportedly outperforms training on prior safety datasets (Self-adaptive Dataset Construction for Real-World Multimodal Safety Scenarios). Two things suggest it will not suffice here. First, the residual ~20% failure rate under demonstrations persists even in the easier physical-harm setting (Safe Semantics, Unsafe Interpretations). Second, pushing alignment harder trades into oversensitivity — USB's 25.82% refusal rate (USB) — and for code agents, refusing legitimate FFI work is a real capability cost. Our decisive check is a head-to-head at matched human-annotation budget, reporting both axes (safe rate and harmless-refusal rate); if demonstrations dominate the verifier on both, the honest conclusion is that GlueBench matters as a benchmark even if the defense belongs in training rather than the loop.

Proposed Experiments and Decisive Checks

Experiment one measures the gap: frontier and open-source multimodal agents on GlueBench, zero-shot, reporting the boundary-safe rate separately for text-only, benign-image, and adversarial-typographic presentations. The hypothesis, calibrated on SIUO (GPT-4V at 53.26% safe rate) and on RedCode's finding that agents scrutinize natural-language instructions less than raw code, is that safe rates will fall below the SSUI zero-shot figures and degrade further in the multimodal presentations — mirroring Omni-SafetyBench's systematic degradation from unimodal to omni-modal input (Omni-SafetyBench: A Benchmark for Safety Evaluation of Audio-Visual Large Language Models). Experiment two measures the defense: the verifier-in-the-loop against the zero-shot, ICL, UniGuard, linter, and edge-ablated configurations, with confirmed-exploit rate and harmless-refusal rate as the paired headline metrics. Experiment three tests generalization: verifier boundary rules authored only for the npm/ctypes patterns, evaluated on the Android-style privilege cases derived from IAceFinder's patterns, to check that the approach transfers across FFI flavors rather than memorizing the seed corpus. The single most decisive number is the gap between the full verifier and its edge-stripped ablation on confirmed exploits; if that gap is small, the boundary was never the problem, and the proposal's central claim fails. All artifacts — the benchmark, the benign counterpart set, and the verifier — will be released, since the field currently has no reported result on Lacuna for any of these questions, and the measurement itself is half the contribution.