Programs and servers
PreviewPreview. An extension can ask Pitwall to run a native helper, keep a local server running, or download a pinned executable. Its component stays in the tile sandbox; native programs run as you, outside that sandbox. The programs permission bounds the commands it may request, and you approve each exact command before it runs.
Use a Setup view for Install, Start, Stop and connection state. Pitwall owns the approval sheet and the Programs section on the extension's page.
- Declare the allowed commands
- Run once
- Keep a server running
- Exact approval and environment
- Private one-time output
- Download a pinned release
- Test without native processes
- Legacy service blocks
Declare the allowed commands
"settings": [
{ "key": "listen", "type": "text", "default": "127.0.0.1:8790" },
{ "key": "apiKey", "type": "secret" }
],
"permissions": {
"programs": {
"reason": "Check the local helper and run its server",
"commands": [
{ "command": "helper", "args": ["--version"] },
{ "command": "helper", "args": ["serve", "--data", "{data}", "--listen", "{setting:listen}"] }
],
"downloads": ["https://downloads.example.com/helper/*"]
}
}
The permission starts off. Its screen lists the patterns exactly as written, and pitwall extension check . validates them.
- Declare 1–16 command patterns. A program is a name resolved on the user's login PATH, or a path under
{data}, such as"{data}/bin/helper-1.2.3". It is never a shell command or an absolute path elsewhere. - Arguments are literals,
*for exactly one argument, or a final**for the remaining arguments. Shells and interpreters cannot use an unrestricted**pattern. A wildcard permits a request; it never replaces the exact-command approval. {data}is the extension's data folder, kept across updates and Go back.{setting:KEY}fills a declared non-secret setting. A setting used by a command is changed through a host-owned setting field; changing it can require a new approval. Secrets cannot appear in arguments or setting substitutions.- Download patterns are optional, at most 16. Each names an exact HTTPS origin;
*matches only its path or query, never a different host.
Run once
use std::time::Duration;
use pitwall_extension::programs::{self, Command};
let task = programs::run(
&Command::new("helper").arg("--version"),
Duration::from_secs(30),
)?;
The task id is returned while approval may still be pending. A matching Event::ProgramFinished(done) later carries done.task, exit, stdout and stderr. A rejected request can complete without an exit code. Show the refusal or failure in the Setup view and let the user try again.
A run lasts at most ten minutes. At most four one-shot runs and downloads may wait or run together; a fifth returns HostError::Busy. Stdout and stderr are bounded to 1 MiB each, with supplied secrets redacted. Ordinary output also goes to the extension's Log.
Keep a server running
let listen = settings::text("listen")
.unwrap_or_else(|| "127.0.0.1:8790".into());
let command = Command::new("helper")
.args(["serve", "--data", "{data}", "--listen", "{setting:listen}"])
.env_secret("HELPER_API_KEY", "apiKey");
programs::start("server", &command, Some(&listen))?;
start supervises a named process group, with at most four supervised programs per extension, separate from the four one-shot/download slots. programs::status("server") reads its state, and Event::ProgramChanged(change) reports changes. States include Asking, Starting, Running, Exited, Failed, Stopped and Denied. Use programs::stop("server") to stop its group, including children.
A supervised program that exits is retried after 1, 5 and 30 seconds, then left failed after the fourth stop. Running for ten minutes resets that sequence. Its page shows Stop, Restart and Log.
The optional listen must be a loopback address with a port. Once the approved program is running, the component can reach exactly that address over HTTP without a separate net grant. Check readiness yourself with cx.fetch; Running alone does not prove your server has answered. This automatic loopback reach ends when the program stops or its permission is revoked.
If something already listens there, the exact start command still needs approval first. After approval, the state says Running elsewhere with no PID: Pitwall neither starts nor kills that unrelated process. Stop or revoke removes the component's temporary HTTP reach without killing it.
Hiding or closing a tile does not stop the program. While programs is granted, its component can continue background work without drawing hidden views; hidden timer ticks are coalesced to at most once a second. Programs stop when the permission is revoked, the extension is turned off, updated or removed, or Pitwall quits. Updates stop the programs before backing up {data} and replacing the extension.
Exact approval and environment
The sheet offers Run, Always and Deny, showing the resolved command, folder, environment references and any loopback HTTP access. A supervised request says that Pitwall will keep it running. Always applies to that exact request: the resolved path, arguments, working folder, environment references, one-shot timeout or supervised mode, output privacy and listen address. A changed request asks again. Allowed lines appear under Programs on the extension's page with Remove; removing one makes future requests ask again and does not cancel a run already started.
Pitwall rechecks the current grant, settings, patterns and resolved path when an approval is answered and before starting. If a valid exact line changed while the sheet was open it asks again; a disallowed one does not run. Revoking permission or turning the extension off also cancels pending approvals.
Programs receive a minimal host environment, including the login PATH and platform essentials such as home, user, locale and temporary-folder variables, plus variables explicitly supplied by Command::env or Command::env_secret. Other inherited credentials, proxies and runtime injection variables are not copied. Explicit environment values are shown on the approval sheet; secret values are represented only by their keys and filled by the host after approval. The component never receives PATH or those secret values through this API. Command::cwd("relative/path") selects an existing folder inside {data}; the default is {data}.
Private one-time output
For a command that returns a one-time sign-in link or another transient credential, add .private_output() to its Command and declare that command's pattern too. The result still has the same output limits and known-secret redaction, but its text is delivered once in Event::ProgramFinished and is not put in Log, Activity, status snapshots or the completion type's Debug output. The host drops its capture after delivery. Consume it promptly and discard it: do not copy it into a tile, storage, logs or an agent reply. This option does not make an untrusted native program safe.
Download a pinned release
use pitwall_extension::programs::Unpack;
// RELEASE_SHA256 is a 64-digit hash pinned in your component's source.
let task = programs::download(
"https://downloads.example.com/helper/1.2.3/helper.gz",
RELEASE_SHA256,
"bin/helper-1.2.3",
Unpack::Gzip,
)?;
Event::DownloadFinished(done) carries the task id and outcome: the new relative path or an error. Downloads use HTTPS without inherited credentials, cookies or proxies. Every redirect must match a declared download pattern too. The SHA-256 covers the downloaded bytes, before unpacking; a mismatch installs nothing.
Use Unpack::None, Zip, TarGz or Gzip. Compressed and unpacked data are each limited to 50 MiB, with at most 5,000 archive entries. Pitwall's readers refuse paths out, links and special files. Plain and gzip file downloads are marked executable; archive files retain their executable bits. The destination must be a new relative path under {data}, with no symlink parents. A download never replaces an existing path: use a new version's destination. Permission revocation cancels the download and prevents publication.
Downloading never runs the result. To execute it, declare a corresponding command pattern such as "{data}/bin/helper-1.2.3" and request run or start; its exact command still asks for approval.
Test without native processes
The harness uses fake program and download tables with the real matching, approval and archive rules. No native helper is spawned.
use pitwall_extension_test::{Approval, Harness, ProgramOutput};
let mut tile = Harness::load(".")
.grant("programs")
.program("helper", ProgramOutput {
exit: 0,
stdout: "1.2.3".into(),
stderr: String::new(),
})
.open("main");
tile.approve_programs(Approval::Deny);
// Exercise your Setup view's Run button and assert nothing ran.
assert!(tile.programs_run().is_empty());
Test Run, Deny, Always, a changed command and removal of Always with approve_programs, program_approvals, programs_run and revoke_program_always. Use crash_program(name) and virtual advance(Duration) for the 1/5/30-second restart sequence, program_status(name) for state, and program_elsewhere(address) for an already-listening server. download_bytes(url, bytes) supplies a fake release: test a correct hash, a wrong hash, a hostile archive and an existing destination. Also test off/revoke, hidden work and private output not appearing in snapshots or logs.
Legacy service blocks
The adapter-era manifest service block and SDK service::* API remain until migration item 8c3 removes them. Existing extensions keep their install action, version probe, confirmed service command, ready.listen loopback reach and Event::ServiceChanged behavior during that transition. New extensions should use programs from their Setup view instead; the legacy service block is not the API described above.