1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//! # Sprites SDK for Rust
//!
//! Official Rust client for the [Sprites](https://sprites.dev) API - stateful sandbox
//! environments from [Fly.io](https://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
//!
//! ```no_run
//! 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`]:
//!
//! ```no_run
//! use sprites::SpritesClient;
//!
//! # #[tokio::main]
//! # async fn main() -> sprites::Result<()> {
//! 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());
//! }
//! # Ok(())
//! # }
//! ```
//!
//! For long-running processes, use [`Command::spawn`] for streaming I/O:
//!
//! ```no_run
//! use sprites::SpritesClient;
//!
//! # #[tokio::main]
//! # async fn main() -> sprites::Result<()> {
//! 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);
//! # Ok(())
//! # }
//! ```
//!
//! ## Checkpoints
//!
//! Create snapshots for instant rollback (~300ms):
//!
//! ```no_run
//! use sprites::SpritesClient;
//!
//! # #[tokio::main]
//! # async fn main() -> sprites::Result<()> {
//! 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?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Network Policies
//!
//! Control what domains your sprite can access:
//!
//! ```no_run
//! use sprites::{SpritesClient, NetworkPolicy, NetworkPolicyRule, PolicyAction};
//!
//! # #[tokio::main]
//! # async fn main() -> sprites::Result<()> {
//! 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?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Feature Flags
//!
//! This crate uses [`rustls`](https://github.com/rustls/rustls) for TLS by default.
//! All async operations require a Tokio runtime.
// Re-export main types
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SessionInfo;
pub use ;
pub use ;