v3: world directory layout (world/ is the VFS root, host/ is host state)

This commit is contained in:
2026-11-06 15:16:18 +00:00
parent 409da85124
commit 964ef978c2
+20 -6
View File
@@ -1,18 +1,32 @@
//! A world folder and the one virtual root that host code and guests share.
//! A world directory and the one virtual root that host code and guests share.
//!
//! Layout of a world directory:
//! - `world/`: the virtual root `/` that every guest sees. Agents change everything in it.
//! - `host/`: host state outside the sandbox (harness storage, later the vault). No guest sees it.
use sausage_vfs::{Host, Layer, Mounts, Process};
use std::{path::Path, sync::Arc};
use std::{
path::{Path, PathBuf},
sync::Arc,
};
/// An open world. `root` is the filesystem every guest sees as `/`; host code (the harness's file
/// tools) reads and writes through the same layer, so both always see the same files.
pub struct World {
pub root: Arc<dyn Layer>,
/// The host state folder, `<dir>/host`.
pub host_dir: PathBuf,
}
impl World {
/// Open the world folder at `path`. The process table adds more mounts (`/proc`, `/run`).
pub fn open(path: &Path) -> anyhow::Result<Self> {
/// Open (and create if missing) the world directory `dir`. The process table adds more mounts
/// (`/proc`, `/run`).
pub fn open(dir: &Path) -> anyhow::Result<Self> {
let root_dir = dir.join("world");
let host_dir = dir.join("host");
std::fs::create_dir_all(&root_dir)?;
std::fs::create_dir_all(&host_dir)?;
let mut mounts = Mounts::default();
mounts.mount("/", Arc::new(Host::new(path, Process::default())?), false);
Ok(World { root: Arc::new(mounts) })
mounts.mount("/", Arc::new(Host::new(&root_dir, Process::default())?), false);
Ok(World { root: Arc::new(mounts), host_dir })
}
}