Expand description
§Sprites SDK for Rust
Official Rust client for the Sprites API - stateful sandbox environments from Fly.io.
Sprites are lightweight, persistent VMs powered by Firecracker. They hibernate when idle (no compute cost) and wake instantly when needed. Create checkpoints in ~300ms and restore to any previous state.
§Quick Start
use sprites::SpritesClient;
#[tokio::main]
async fn main() -> sprites::Result<()> {
// Create a client with your API token
let client = SpritesClient::new(std::env::var("SPRITES_TOKEN").unwrap());
// Create a sprite
let sprite = client.create("my-sprite").await?;
// Run a command
let output = sprite.command("uname").arg("-a").output().await?;
println!("{}", output.stdout_str());
// Create a checkpoint
let checkpoint = sprite.checkpoint("Initial state").await?;
println!("Checkpoint: {}", checkpoint.id);
// Clean up
sprite.destroy().await?;
Ok(())
}§Command Execution
The Command struct mirrors std::process::Command:
use sprites::SpritesClient;
let client = SpritesClient::new("token");
let sprite = client.sprite("my-sprite");
let output = sprite
.command("npm")
.arg("install")
.current_dir("/app")
.env("NODE_ENV", "production")
.output()
.await?;
if output.success() {
println!("stdout: {}", output.stdout_str());
}For long-running processes, use Command::spawn for streaming I/O:
use sprites::SpritesClient;
let client = SpritesClient::new("token");
let sprite = client.sprite("my-sprite");
let mut child = sprite.command("npm").arg("run").arg("dev").spawn().await?;
// Wait for completion and get output
let status = child.wait().await?;
println!("Process exited with: {:?}", status);§Checkpoints
Create snapshots for instant rollback (~300ms):
use sprites::SpritesClient;
let client = SpritesClient::new("token");
let sprite = client.sprite("my-sprite");
// Create a checkpoint before risky operations
let checkpoint = sprite.checkpoint("Before migration").await?;
// Run migrations...
sprite.command("npm").arg("run").arg("migrate").output().await?;
// If something goes wrong, restore instantly
sprite.restore(&checkpoint.id).await?;§Network Policies
Control what domains your sprite can access:
use sprites::{SpritesClient, NetworkPolicy, NetworkPolicyRule, PolicyAction};
let client = SpritesClient::new("token");
let sprite = client.sprite("my-sprite");
let policy = NetworkPolicy {
rules: vec![
NetworkPolicyRule {
domain: "api.anthropic.com".into(),
action: PolicyAction::Allow,
},
NetworkPolicyRule {
domain: "*.npmjs.org".into(),
action: PolicyAction::Allow,
},
NetworkPolicyRule {
domain: "*".into(),
action: PolicyAction::Deny,
},
],
include: vec![],
};
sprite.set_policy(policy).await?;§Feature Flags
This crate uses rustls for TLS by default.
All async operations require a Tokio runtime.
Structs§
- Attach
Command - A command to attach to an existing session
- Checkpoint
- Checkpoint information
- Child
- A handle to a running command in a sprite
- Child
Stderr - Handle for reading from a child’s stderr
- Child
Stdin - Handle for writing to a child’s stdin
- Child
Stdout - Handle for reading from a child’s stdout
- Command
- A command to execute in a sprite
- DirEntry
- Entry in a directory listing
- Exec
Options - Execution options for commands
- Exit
Status - Exit status from a command
- File
Info - Information about a file
- Filesystem
- Handle for filesystem operations on a sprite
- List
Checkpoints Options - Options for listing checkpoints
- List
Checkpoints Response - Response from listing checkpoints
- List
Options - Options for listing sprites
- List
Sprites Response - Response from listing sprites
- Network
Policy - Network policy configuration
- Network
Policy Rule - Network policy rule
- Output
- Command output
- Port
Mapping - A mapping from a local port to a remote port
- Proxy
Session - An active proxy session forwarding traffic to a sprite
- Service
LogEntry - A log entry from a service
- Service
LogStream - Stream of service log entries
- Service
Request - Request to create or update a service
- Service
State - Current state of a service
- Session
- Active execution session
- Session
Info - Information about an active session
- Sprite
- Handle to a sprite
- Sprite
Config - Sprite configuration
- Sprite
Info - Full sprite information returned by the API
- Sprites
Client - Sprites API client
- Sprites
Client Builder - Builder for configuring a SpritesClient
- UrlSettings
- URL settings for a sprite
- Version
- Server version information
Enums§
- Error
- Errors that can occur when interacting with the Sprites API
- Policy
Action - Network policy action
- Service
Status - Service status
- Signal
- Unix signal to send to a service
- Sprite
Status - Sprite status
- Stream
Message - Streaming message types for checkpoints and exec
- UrlAuth
- URL authentication settings
Type Aliases§
- Result
- Result type alias for Sprites operations