---
title: Storage
sidebarTitle: Storage
description: Inspect local storage usage and preview cleanup from the SDK.
icon: "database"
---

Storage reporting and cleanup are local-only. See [storage commands](/cli/storage-commands) for what is measured and what cleanup removes.

Storage accounting and pruning are available through TypeScript, Rust, Python, and Go. Ruby does not expose these APIs.

## Inspect usage and preview cleanup

SDK pruning is explicit and has no interactive confirmation. Preview the cleanup before removing files:

<CodeGroup>
```typescript TypeScript
// Byte fields are bigint to preserve the full unsigned 64-bit range.
// Unknown values are null.
import { Storage } from "microsandbox";

const usage = await Storage.usage();
const preview = await Storage.prune({ dryRun: true, olderThanSeconds: 600 });
```

```rust Rust
use std::time::Duration;

use microsandbox::storage::MemoryPruneOptions;
use microsandbox::{Sandbox, Snapshot, Storage};

// Uses the same accounting and reclamation implementation as the CLI.
// Storage::usage_local and Storage::prune_local accept an explicit LocalBackend.
let usage = Storage::usage().await?;
let sandbox_storage = Sandbox::get("worker").await?.storage_usage().await?;
let snapshot_storage = Snapshot::open("worker:ready").await?.storage_usage().await?;
let preview = Storage::prune(&MemoryPruneOptions {
    dry_run: true,
    older_than: Duration::from_secs(600),
    ..Default::default()
}).await?;
```

```python Python
# Byte fields are integers; unknown values are None.
from microsandbox import Storage

usage = await Storage.usage()
preview = await Storage.prune(dry_run=True, older_than_seconds=600)
```

```go Go
// Byte fields are unsigned integers; nullable measurements use pointers.
usage, err := microsandbox.StorageUsage(ctx)
if err != nil {
    return err
}
preview, err := microsandbox.PruneStorage(ctx, microsandbox.StoragePruneOptions{
    DryRun: true,
    OlderThanSeconds: 600,
})
if err != nil {
    return err
}
```
</CodeGroup>

The SDKs expose aggregate reports and ownership checks. Prune reports retain per-file errors alongside successful removals; inspect the report's entries.

<Accordion title="Per-object accounting and shared memory">

Object methods retain the backend captured by their handles. Per-object storage measures managed files and describes exclusions. Exact attribution of shared RAM to individual sandboxes is not currently available; aggregate memory accounting reports whether pins or handoffs retain it.

</Accordion>
