Complete API reference for the Malbox C++20 Plugin SDK. For a step-by-step walkthrough, see the Creating a C++ Plugin guide.Documentation Index
Fetch the complete documentation index at: https://docs.malbox.app/llms.txt
Use this file to discover all available pages before exploring further.
Plugin Base Class
Every plugin subclassesmalbox::Plugin and implements on_task at minimum. All other methods have default no-op implementations.
Lifecycle Methods
on_task (required)
Called for each assigned analysis task. This is where your analysis logic lives. Push results to the daemon via ctx.push_result().
Handle to the current task. Provides access to the sample and task configuration. Non-owning, do not store.
Runtime communication handle for pushing results, emitting progress, warnings, and events. Non-owning, do not store.
on_start
Called once before any tasks arrive. Use for initialization.
Key-value configuration map from the daemon and
plugin.toml settings.on_stop
Called once on shutdown. Clean up resources here.
health_check
Called periodically by the runtime to check plugin health.
A struct with
ready (bool) and reason (string) fields.Event Handlers
Override these to react to system events. All are optional and default to no-ops. See the Events Reference for the full list of events in each category.on_daemon_event
Triggered by system-wide events such as shutdown or configuration reload.
The daemon event that occurred (
DaemonShutdown or ConfigReloaded).Runtime communication handle.
on_task_event
Triggered by task lifecycle events (created, starting, completed, failed).
The task event that occurred.
Contains the
task_id of the affected task.Runtime communication handle.
on_plugin_event
Triggered by plugin process events (started, stopped, result produced).
The plugin event that occurred.
Contains the
plugin_id of the affected plugin.Runtime communication handle.
on_sample_event
Triggered by sample processing events (started, stopped, result produced).
The sample event that occurred.
Contains the
sample_id of the affected sample.Runtime communication handle.
Task
Provides access to the current analysis task.Task is a non-owning handle, valid only during the on_task callback. Do not store it.
id()
Unique identifier for this task.
sample_path()
Absolute path to the sample on disk.
sample_bytes()
Reads the entire sample file into memory. Throws malbox::Error on I/O failure.
The raw bytes of the sample file.
config()
All configuration key-value pairs for this task.
config_value()
The configuration key to look up.
The value if found, or
std::nullopt.Context
Used to communicate with the runtime during task execution.Context is a non-owning handle, valid only during the callback. Do not store it.
push_result()
Pushes a single result to the daemon. Call one or more times during on_task to stream results incrementally.
The result to send to the daemon.
emit_progress()
Reports task progress to the runtime.
Progress value clamped to
[0.0, 1.0].Human-readable status message (e.g.
"scanning signatures").warn()
Attaches a warning message to the task report.
The warning message to attach.
mark_collected()
Marks a file as already handled, preventing artifact auto-collection from sending it again.
Use this when a plugin reads a file from the artifacts directory, processes it, and sends derived data as Json/Bytes instead of the raw file. Files sent via push_result(PluginResult::file(...)) are automatically marked.
Absolute path to the file to mark as handled.
emit_event()
Emits a raw system event. This is an advanced escape hatch for custom event routing.
The event to emit.
The event payload.
PluginResult
Pushed viactx.push_result() during on_task to report analysis findings. Each result name should correspond to a [results.*] entry in your plugin.toml.
PluginResult::json()
Creates a JSON-encoded result from raw UTF-8 bytes.
Result identifier matching a
[results.*] key in plugin.toml.Raw UTF-8 encoded JSON bytes.
PluginResult::bytes()
Creates a raw binary result.
Result identifier matching a
[results.*] key in plugin.toml.Raw binary data.
PluginResult::file()
Creates a result referencing a file on disk. The runtime reads the file contents.
Result identifier matching a
[results.*] key in plugin.toml.Absolute filesystem path to the result file.
Report
#include <malbox/report.hpp>
A structured result envelope with semantic metadata and a presentation layer for frontend rendering. All report types live in the malbox::report namespace.
Report
to_json()
Serializes a report to a JSON string.
into_plugin_result()
Serializes a report and wraps it as a PluginResult with the well-known name "report".
PluginInfo
Semantic Types
Classification
Confidence
Verdict
Indicator
IOC with an open-vocabulary kind (e.g. "sha256", "ipv4", "domain", "yara_rule").
Ttp
MITRE ATT&CK technique reference.
ArtifactRef
Reference to a sibling PluginResult by name.
Presentation Types
Section
Block
A std::variant of all supported block types:
Block Types
| Type | Fields |
|---|---|
BlockMarkdown | text |
BlockCallout | level (CalloutLevel), text |
BlockHeading | level (1-6), text |
BlockDivider | (none) |
BlockKv | pairs (std::vector<KvPair>) |
BlockTable | columns (std::vector<Column>), rows_json (std::vector<std::string>), sortable, searchable |
BlockCode | language, text |
BlockJson | data_json (pre-encoded), collapsed |
BlockHex | bytes_b64, offset |
BlockImage | artifact (result name), caption |
BlockDownload | artifact (result name), label |
BlockIocs | items (std::vector<Indicator>) |
BlockTtps | items (std::vector<Ttp>) |
BlockTree | nodes (std::vector<TreeNode>) |
BlockTimeline | events (std::vector<TimelineEvent>) |
BlockGraph | nodes (std::vector<GraphNode>), edges (std::vector<GraphEdge>) |
CalloutLevel
Helper Structs
ReportBuilder
Fluent API for constructing a Report.
SectionBuilder
Fluent API for constructing a Section with typed blocks.
Constants
PluginMeta
Metadata passed to the runtime at startup. All string fields must be null-terminated string literals with static lifetime.Plugin identifier. Must be alphanumeric with
- and _ only.Semver version string (e.g.
"0.1.0").Human-readable description. Nullable.
Author name(s).
PluginType::Host or PluginType::Guest.PluginState::Persistent, PluginState::Ephemeral, or PluginState::Scoped.ExecutionContext::Exclusive, Sequential, Parallel, or Unrestricted.Enums
- PluginType
- PluginState
- ExecutionContext
| Value | Description |
|---|---|
PluginType::Guest | Runs inside a VM/container, communicates via gRPC |
PluginType::Host | Runs on the daemon machine, communicates via IPC |
RuntimeConfig
Runtime configuration baked into the plugin binary at build time. Generated fromplugin.toml by malbox-codegen (invoked via CMake’s malbox_generate_runtime_config).
gRPC listen port.
Absolute path to the directory where the daemon pushes the sample for analysis.
Absolute path to the directory where the plugin writes output artifacts.
Absolute path to the internal result stash spillover directory.
Absolute path to the SDK-internal log overflow files directory.
Absolute path to external log files directory (kernel drivers, custom tools). Auto-collected after task execution.
Result stash spill threshold in bytes.
Result stash entry TTL in seconds.
Tracing
EnvFilter directive string (e.g. "info", "info,hyper=warn").Auto-collection settings for artifact files. Contains
enabled, include/exclude glob patterns, and max_file_size.Auto-collection settings for external log files. Contains
enabled, include/exclude glob patterns, and max_file_size.Runtime Entry Points
malbox::Error on failure.
Owning pointer to your plugin instance.
Plugin metadata describing name, version, type, state, and execution context.
Compile-time runtime configuration generated from
plugin.toml. Required for guest plugins only.Error Handling
Plugin methods can throwmalbox::Error to signal failures. The SDK catches exceptions at the FFI boundary and reports them to the runtime.
Numeric error code. Use
-1 for generic failures.Human-readable error description.
task.sample_bytes()) also throw malbox::Error on failure.
Thread Safety
When usingExecutionContext::Parallel, multiple on_task calls may execute concurrently. Protect shared mutable state with std::mutex or similar. Health checks may also arrive on a different thread regardless of execution context.
Headers
| Header | Contents |
|---|---|
malbox/plugin.hpp | Umbrella header (include this one) |
malbox/error.hpp | malbox::Error exception class |
malbox/types.hpp | Enums, PluginMeta, HealthStatus |
malbox/events.hpp | Event types and payloads |
malbox/task.hpp | malbox::Task wrapper |
malbox/context.hpp | malbox::Context wrapper |
malbox/result.hpp | malbox::PluginResult |
malbox/report.hpp | malbox::report::Report, builders, semantic types, and block types |
malbox/handlers.hpp | malbox::Plugin base class |
malbox/runtime.hpp | Entry points, RuntimeConfig, and trampolines |
malbox_runtime_config.hpp | Generated compile-time constexpr RuntimeConfig from plugin.toml |