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.
Handle to the current task. Provides access to the sample and task configuration. Non-owning, do not store.
Runtime communication handle for emitting progress, warnings, and events. Non-owning, do not store.
One or more analysis results. Each result name should match a
[results.*] entry in your plugin.toml.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.
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.
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
Returned fromon_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.
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 |
Runtime Entry Points
malbox::Error on failure.
Owning pointer to your plugin instance.
Plugin metadata describing name, version, type, state, and execution context.
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/handlers.hpp | malbox::Plugin base class |
malbox/runtime.hpp | Entry points and trampolines |