Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(file_write): cap the content a single write may carry\n\nThe tool accepted content of any size, and a regression case for that sat\ndisabled because there was nothing to assert against. Five megabytes, checked\nafter the autonomy gate so a read-only company is told it is read-only rather\nthan told its content is too large.\n

oxoxDevd61549e1c6d3
diff --git a/src/openhuman/tools/impl/filesystem/file_write.rs b/src/openhuman/tools/impl/filesystem/file_write.rs
index bcfbeb1f1a..742f4819fe 100644
--- a/src/openhuman/tools/impl/filesystem/file_write.rs
+++ b/src/openhuman/tools/impl/filesystem/file_write.rs
@@ -6,6 +6,8 @@ use serde_json::json;
use std::sync::Arc;
use tinytools::ToolRunContext;
+const MAX_CONTENT_BYTES: usize = 5 * 1024 * 1024;
+
/// Write file contents with path sandboxing
pub struct FileWriteTool {
security: Arc<SecurityPolicy>,
@@ -136,6 +138,13 @@ impl FileWriteTool {
));
}
+ if content.len() > MAX_CONTENT_BYTES {
+ return Ok(ToolResult::error(format!(
+ "Content too large: {} bytes (limit: {MAX_CONTENT_BYTES} bytes)",
+ content.len()
+ )));
+ }
+
if self.security.is_rate_limited() {
return Ok(ToolResult::error(
"Rate limit exceeded: too many actions in the last hour",
diff --git a/src/openhuman/tools/impl/filesystem/file_write_tests.rs b/src/openhuman/tools/impl/filesystem/file_write_tests.rs
index d3011c1552..ef56601abf 100644
--- a/src/openhuman/tools/impl/filesystem/file_write_tests.rs
+++ b/src/openhuman/tools/impl/filesystem/file_write_tests.rs
@@ -336,11 +336,9 @@ async fn file_write_blocks_null_byte_in_path() {
let _ = tokio::fs::remove_dir_all(&dir).await;
}
-/// `file_write` has no content-size cap — unlike `file_read`'s 10MB read cap,
-/// `edit_file`'s 5MB and `grep`'s 5MB file caps, nothing here bounds how much
-/// an agent can write into the sandbox in one call.
+/// `file_write` enforces the same 5MB content-size cap as `edit_file` and
+/// `grep`'s file caps (`file_read` allows up to 10MB for reads).
#[tokio::test]
-#[ignore = "confirms fail-open: file_write enforces no content-size cap, unlike its sibling tools"]
async fn file_write_refuses_an_oversized_content_write() {
let dir = std::env::temp_dir().join("openhuman_test_file_write_oversized");
let _ = tokio::fs::remove_dir_all(&dir).await;