Skip to main content

A MAL compliant simulator.

Project description

MAL Simulator

Overview

The MAL Simulator is a tool designed for running simulations on systems modeled in the Meta Attack Language (MAL).

It allows you to:

  • Simulate the adversarial and defensive actions of intelligent agents (attackers and defenders).
  • Analyze system security and evaluate attack/defense strategies.
  • Develop machine learning agents (e.g., using Reinforcement Learning) in a safe, dynamic environment.
  • Incorporate stochastic modeling through Time-to-Compromise (TTC) distributions.

For in-depth documentation, refer to:

The simulator also has a DOI at the KTH Open and FAIR Data repository for easier referencing: 10.71775/kth.gx42q-9m748

Contributing

  • Use Conventional commits
  • The CI pipeline runs pytest, mypy and ruff format && ruff check for linting and type checking. PRs will only be merged if pipeline succeeds.

Making a release

  • Make a release PR (called release-x.y.z) with your changes. Update version number in pyproject.toml and malsim/__init__.py.
  • Merge the PR after the pipeline suceeds
  • Tag the latest commit with the new version number
  • Push the tag

🛠️ How to Run a Simulation

1. Installation

pip install mal-simulator

To also get ML dependencies (pettingzoo, gymnasium):

pip install mal-simulator[ml]

For additional dev tools:

pip install mal-simulator[dev]

2. Running a Scenario via CLI

You can execute a simulation using a YAML scenario file, which defines the MAL model, the agents (attackers and defenders), their policies, and their goals.

The basic command structure is:

malsim <scenario_file> [options]

Example

Execute a simulation defined in my_scenario.yml:

malsim my_scenario.yml

Common Options:

Option Description
-s, --seed SEED Sets the random seed for deterministic simulations.
-t, --ttc-mode MODE Sets the Time-to-Compromise mode (e.g., DISABLED, PER_STEP_SAMPLE).
-g, --send-to-gui Sends simulation data to the malsim-gui for visualization (requires the GUI to be running).

3. Programmatic Usage

For advanced and customized simulations (e.g., integrating with a custom ML training loop), you can initialize and run the simulator directly in a Python script:

from malsim import MalSimulator, run_simulation, Scenario

# 1. Load the scenario configuration
SCENARIO_FILE = "my_scenario.yml"
scenario = Scenario.load_from_file(SCENARIO_FILE)

# 2. Create the simulator instance
sim = MalSimulator.from_scenario(scenario)

# 3. Run the simulation
agent_actions = run_simulation(sim, scenario.agents)

print("Simulation finished. Agent actions:", agent_actions)

You can also run your own simulation loop.

from malsim import MalSimulator, Scenario

scenario = Scenario.load_from_file("my_scenario.yml")
sim = MalSimulator.from_scenario(scenario)
agent_states = sim.reset()

while not sim.done():
    # ... calculate actions for each agent
    agent_states = sim.step(actions)

Read the Wiki for more ways to run the simulator.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mal_simulator-3.2.0.tar.gz (80.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mal_simulator-3.2.0-py3-none-any.whl (81.5 kB view details)

Uploaded Python 3

File details

Details for the file mal_simulator-3.2.0.tar.gz.

File metadata

  • Download URL: mal_simulator-3.2.0.tar.gz
  • Upload date:
  • Size: 80.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mal_simulator-3.2.0.tar.gz
Algorithm Hash digest
SHA256 bfc24da3e1a14890bb12c893e875058f44962893be14775b7fd3039bef20fb21
MD5 53b9b66535efed62ba70960cde0a9a5b
BLAKE2b-256 bd8bdfc0017a9609d09fa95a57b1de7f3572eaf4c1e6970ee9c04c855fb6d5c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mal_simulator-3.2.0.tar.gz:

Publisher: publish-to-pypi-and-test-pypi.yml on mal-lang/mal-simulator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mal_simulator-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: mal_simulator-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 81.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mal_simulator-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5971c9363ca96c26b0bca8d5e4186f62735deec25d6044b7e0fa84c290253cf2
MD5 cdbb9afabf4c392cb837f660ccf620b5
BLAKE2b-256 af1d0cec1a02f67f4030ad0d65f71f1731229cd76993b257589f8c263c3cdfab

See more details on using hashes here.

Provenance

The following attestation bundles were made for mal_simulator-3.2.0-py3-none-any.whl:

Publisher: publish-to-pypi-and-test-pypi.yml on mal-lang/mal-simulator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page