Run Python code in a MicroPython/WASM sandbox
Project description
datasette-agent-micropython
Run Python code in a MicroPython/WASM sandbox
Installation
Install this plugin in the same environment as Datasette.
datasette install datasette-agent-micropython
Usage
This plugin adds an execute_micropython tool to
Datasette Agent. The tool runs
Python code using a sandboxed MicroPython interpreter compiled to WASM.
Use it for pure computation, parsing, data transformation, math, and checking
algorithms. Output is captured from stdout and stderr, so code should use
print() to return values:
print(sum(range(10)))
Each Datasette Agent conversation gets its own persistent MicroPython interpreter. Variables, imports, and functions defined in one tool call can be reused later in the same conversation:
def fib(n):
a, b = 0, 1
out = []
for _ in range(n):
out.append(a)
a, b = b, a + b
return out
print(fib(10))
That state is not shared with other conversations. Use reset_context=true to
clear the current conversation's interpreter before running code. If execution
times out, exhausts fuel, or traps the WASM runtime, that conversation's
interpreter is discarded and the next call starts fresh.
No network APIs are available, and no host filesystem is exposed by default.
The MicroPython environment includes a read_only_sql_query() helper for
querying Datasette databases:
result = read_only_sql_query(
"data",
"select name, qty from items where qty > :min_qty",
{"min_qty": 2},
)
print(result["columns"])
print(result["rows"])
It accepts name_of_database, sql, and an optional params dict. It uses the
current actor's execute-sql permission and returns a dict containing
columns, rows, and truncated, or an error key.
The tool accepts:
python- MicroPython code to executereset_context- clear this conversation's interpreter before runningshow_result- render the code and captured output inline for the user
Use show_result=true when the user asked to see the code or output, or when
showing both would help with explanation, debugging, teaching, or
reproducibility. The rendered HTML shows the executed code, then the captured
stdout. When this is set, the tool result tells the agent that the output has
already been shown to the user and does not need to be repeated. Leave it unset
for scratch calculations.
Configuration
Configure the plugin using Datasette plugin settings:
plugins:
datasette-agent-micropython:
max_sessions: 16
wall_clock_timeout_seconds: 5.0
memory_bytes: 16777216
fuel: 10000000
max_output_chars: 10000
Settings:
max_sessions- maximum live conversation interpreters to keep; defaults to16. The least recently used interpreter is closed when the limit is exceeded.wall_clock_timeout_seconds- timeout for each code execution; defaults to5.0.memory_bytes- maximum WebAssembly linear memory for each interpreter; defaults to16777216(16MB).fuel- Wasmtime fuel budget refreshed for each execution; defaults to10000000.max_output_chars- maximum captured output/error characters returned to the model; defaults to10000.
Development
To set up this plugin locally, first checkout the code. You can confirm it is available like this:
cd datasette-agent-micropython
# Confirm the plugin is visible
uv run datasette plugins
To run the tests:
uv run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datasette_agent_micropython-0.1a0.tar.gz.
File metadata
- Download URL: datasette_agent_micropython-0.1a0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aff205fb4aeb31efe6263276eda1b09f10835ba14fcc8b34c708eb0ff457c20f
|
|
| MD5 |
242ffa32348528e16d00723946f8243c
|
|
| BLAKE2b-256 |
ca9aabaf729d2aa076702be2f87364a243ca7bc86b1b9f94d3507c3005d5e158
|
Provenance
The following attestation bundles were made for datasette_agent_micropython-0.1a0.tar.gz:
Publisher:
publish.yml on datasette/datasette-agent-micropython
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
datasette_agent_micropython-0.1a0.tar.gz -
Subject digest:
aff205fb4aeb31efe6263276eda1b09f10835ba14fcc8b34c708eb0ff457c20f - Sigstore transparency entry: 1705132268
- Sigstore integration time:
-
Permalink:
datasette/datasette-agent-micropython@4ce9a3dd89dbc67e51e067d1e2e154dc5e316ae6 -
Branch / Tag:
refs/tags/0.1a0 - Owner: https://github.com/datasette
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4ce9a3dd89dbc67e51e067d1e2e154dc5e316ae6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file datasette_agent_micropython-0.1a0-py3-none-any.whl.
File metadata
- Download URL: datasette_agent_micropython-0.1a0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b8207e48beccebb9cf62caed7d92666de3a08abbcb7e5d23039cbbec7ddbe98
|
|
| MD5 |
9a606071818f821b023a20e73ce0b183
|
|
| BLAKE2b-256 |
e2c78a64d677058d7665ecf04b9107f0d6a1edc17c2959691ef869e691b2f0a6
|
Provenance
The following attestation bundles were made for datasette_agent_micropython-0.1a0-py3-none-any.whl:
Publisher:
publish.yml on datasette/datasette-agent-micropython
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
datasette_agent_micropython-0.1a0-py3-none-any.whl -
Subject digest:
8b8207e48beccebb9cf62caed7d92666de3a08abbcb7e5d23039cbbec7ddbe98 - Sigstore transparency entry: 1705132340
- Sigstore integration time:
-
Permalink:
datasette/datasette-agent-micropython@4ce9a3dd89dbc67e51e067d1e2e154dc5e316ae6 -
Branch / Tag:
refs/tags/0.1a0 - Owner: https://github.com/datasette
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4ce9a3dd89dbc67e51e067d1e2e154dc5e316ae6 -
Trigger Event:
release
-
Statement type: